Difference between revisions of "User-defined properties"
Jump to navigation
Jump to search
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | == User | + | == User-defined Properties == |
Properties can be created and added to objects dynamically at runtime, either from within a custom Action or in response to a hook. For instance, a custom text field could be added to all Shapes when they are created in response to the <tt>object_created</tt> hook: | Properties can be created and added to objects dynamically at runtime, either from within a custom Action or in response to a hook. For instance, a custom text field could be added to all Shapes when they are created in response to the <tt>object_created</tt> hook: | ||
Line 14: | Line 14: | ||
</source> | </source> | ||
+ | |||
+ | User-defined properties can be removed using <tt>object.removeProperty</tt>. | ||
+ | |||
+ | The <tt>Property()</tt> constructor has the following signature: | ||
+ | <source lang="python" enclose> | ||
+ | Property(id, label, value, info=None, tooltip=None) | ||
+ | </source> | ||
+ | |||
+ | The property type will be inferred from <tt>value</tt>. Currently supported types are boolean, number, list, and string. Depending on the type, <tt>info</tt> should also point to a dictionary containing additional information. | ||
+ | |||
+ | {| class="wikitable" | ||
+ | |+ User-defined Properties | ||
+ | ! Property type!!value type!!info dictionary members | ||
+ | |- | ||
+ | |boolean||True, False||ignored | ||
+ | |- | ||
+ | |number||float||<tt>min=0.0</tt>, <tt>max=100.0</tt> | ||
+ | |- | ||
+ | |list||integer (index)||<tt>items=["Item 1", "Item 2"]</tt> | ||
+ | |- | ||
+ | |string||string||<tt>type=string (default),dir,path,label</tt> | ||
+ | |- | ||
+ | |} |
Latest revision as of 20:38, 22 November 2016
User-defined Properties
Properties can be created and added to objects dynamically at runtime, either from within a custom Action or in response to a hook. For instance, a custom text field could be added to all Shapes when they are created in response to the object_created hook:
def add_character_name_prop(shape):
if shape.isType("Shape"):
if not shape.property("character_name"):
prop = Property("character_name", "Character Name", "", {})
shape.addProperty(prop)
import hook
hook.add("object_created", add_character_name_prop)
User-defined properties can be removed using object.removeProperty.
The Property() constructor has the following signature:
Property(id, label, value, info=None, tooltip=None)
The property type will be inferred from value. Currently supported types are boolean, number, list, and string. Depending on the type, info should also point to a dictionary containing additional information.
Property type | value type | info dictionary members |
---|---|---|
boolean | True, False | ignored |
number | float | min=0.0, max=100.0 |
list | integer (index) | items=["Item 1", "Item 2"] |
string | string | type=string (default),dir,path,label |