Scripted objects

From LabRPS Documentation
Jump to navigation Jump to search

Introduction

Besides the standard object types such as variance, modulations and other RPS objects, LabRPS also offers the amazing possibility to build 100% python-scripted parametric objects, called Python Features. Those objects will behave exactly as any other LabRPS object, and are saved and restored automatically on file save/load.

One particularity must be understood: For security reasons, LabRPS files never carry any embedded code. The Python code that you write to create parametric objects is never saved inside a file. This means that if you open a file containing such an object on another machine, if that python code is not available on that machine, the object won't be fully recreated. If you distribute such objects to others, you will need to distribute your Python script too, for example as a Macro.

Note: It is possible to pack python code inside a LabRPS file using json serializing with an App::PropertyPythonObject, but that code can never directly be run, and therefore has little use for our purpose here.

Python Features follow the same rule as all LabRPS features: they are separated into App and GUI parts. The app part, the Document Object, defines the non-GUI aspect of our object, while its GUI part, the View Provider Object, defines how the object will be drawn on screen. The View Provider Object, as any other LabRPS feature, is only available when you run LabRPS in its own GUI. There are several properties and methods available to build your object. Properties must be of any of the predefined properties types that LabRPS offers, and will appear in the property view window, so they can be edited by the user. This way, FeaturePython objects are truly and totally parametric. you can define properties for the Object and its ViewObject separately.

Basic example

To do