Expose Python scripts parameters

Expose Python scripts parameters

Configurable parameter for scripts

To expose parameters in the Tool, start the script with your variables declarations as follows (one per line): the name of the variable, followed by a colon, and the constructor of the object.
Here is a list of the most used parameters:
myBool: Oil.Boolean(True) #constructed with an optional bool argument

#constructed with an optional int argument  
myInt: Oil.Integer(-42) 
myIntPositive : Oil.PositiveInteger(86)
#constructed with an optional float argument
myReal: Oil.Real(25.4)
myRealPositive: Oil.PositiveReal(55.1)
myMeters: Oil.Meters(-18.4)
myPositiveMeters: Oil.PositiveMeters(95.4)
mySeconds: Oil.Seconds(60.0)

myPercentage: Oil.Percentage(0.4)
myPercentageUnbound: Oil.UnboundedPercentage(1.2)

myString: Oil.String("Hello Smode") #constructed with an optional string argument

#constructed with optional named arguments, such as "red", "green", "blue", "alpha", "hue", "saturation" and "value"
myColor: Oil.HsvColor(red = 0.4, blue = 0.5, green = 0.1,alpha = 0.5)
myColorHsv: Oil.HsvColor(hue = 0.4, saturation = 0.8, value = 0.4,alpha = 1.0)

myfilePath: Oil.NativeFile() #path to a file in windows
mySelection: Oil.Selection() #selection of layer/object
myPointer: Oil.WeakPointer() #Pointer to a parameter (use script.myPointer.get() to retrieve the pointed object)
For instance, the following code will display a widget for an Integer and a selector of cameras of the project:
myInt: Oil.Integer()
linkToCamera: Oil.createObject("WeakPointer(Camera)")
All variables exposed by the script are accessible as children properties of the script object. Following the previous example, the first exposed variable can be accessed by script.myInt . Beware: this is an instance of Oil.Integer, you need to call the get() method to retrieve a Python int.
For any object, you can access a variable by its name( getVariableByName ), or iterate through them with the methods getNumVariables and getVariable (that takes the index as a parameter).
You can use Oil.createObject() to create any type of parameter you want that are not build-in the python implementation
my3dPosition: Oil.createObject("Position3d")
myAngles: Oil.createObject("EulerAngles")
my3dSize: Oil.createObject("Size3d(Real)")
Set default value of this variable you can add **kwargs to the createObject function that correspond to the created object, like below
my3dPosition: Oil.createObject("Position3d",x=1.0,y=2.1,z=-5.5)
myAngles: Oil.createObject("EulerAngles",x=2.0,y=0.2,z=3.14)
my3dSize: Oil.createObject("Size3d(Real)",x=0.5,y=0.9,z=1.1)
You can create parameters that point to Object
percentageSelector: Oil.createObject("WeakPointer(Percentage)")
cameraSelector: Oil.createObject("WeakPointer(Camera)")
textureGeneratorSelector: Oil.createObject("WeakPointer(TextureGenerator)")
layerSelector: Oil.createObject("WeakPointer(AnnotatedElement)")
ContentMap: Oil.createObject("SceneTargetWeakPointer")

See Also: