Difference between revisions of "User-defined properties"
Jump to navigation
Jump to search
(Created page with "== 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,...") |
|||
Line 4: | Line 4: | ||
<source lang="python" enclose> | <source lang="python" enclose> | ||
+ | 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) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</source> | </source> |
Revision as of 19:20, 21 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)