blender/doc/python_api/examples/bpy.props.4.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
872 B
Python
Raw Normal View History

"""
Update Example
++++++++++++++
It can be useful to perform an action when a property is changed and can be
used to update other properties or synchronize with external data.
All properties define update functions except for CollectionProperty.
.. warning::
2023-08-24 11:37:29 +10:00
Remember that these callbacks may be executed in threaded context.
.. warning::
2023-08-24 11:37:29 +10:00
If the property belongs to an Operator, the update callback's first
parameter will be an OperatorProperties instance, rather than an instance
of the operator itself. This means you can't access other internal functions
of the operator, only its other properties.
"""
import bpy
2011-06-21 17:17:51 +00:00
def update_func(self, context):
print("my test function", self)
2018-06-26 19:41:37 +02:00
bpy.types.Scene.testprop = bpy.props.FloatProperty(update=update_func)
bpy.context.scene.testprop = 11.0
# >>> my test function <bpy_struct, Scene("Scene")>