Showing an object dynamic property on a UI panel

The Blender API recommends creating custom object properties through the predefined bpy.props classes. For example, the bpy.props.IntProperty class is used to add an integer property. These properties are convenient, work well, and are easy to display on the user interface panels.

However, they are registering in bpy.types and any new property becomes available for all objects of a specific type, not just for the current object. Sometimes, when writing a script, it is much more useful to add the required dynamic property to only one or several objects in the scene.

Adding such a dynamic property to an object is very simple – for example, let’s add an integer property named “dynamic_prop1” to the active object and set it to 35.

Now we can access this object’s property in the script code:

But if we try to place it on the user panel in the usual way,

Blender will through an error:

RnaUiIremR: property not found: Object.dynamic_prop1

To display such a property on the user panel with no errors, we just need to change the format of the property name in the “property” parameter of the “prop” function. The dynamic property name must be enclosed in square brackets and enclosed in quotation marks:

Now the dynamic property will be correctly showed on the UI panel and can be changed through the user interface.


*.blend file with an example of showing a dynamic property of an object on a custom UI panel

4 1 vote
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments