We can assign additional custom properties to objects in Blender using the Blender Python API. Custom properties can be assigned to objects in the common way, using the “bpy.props” class objects, or by simply assigning the desired property to the object. However, while the first method immediately provides a set of controls for managing the property, such as maximum and minimum value constraints, default values, etc., the second method has no such defaults for the assigned property.
However, the Blender API allows us to create control capabilities even for simple dynamic properties assigned to objects.
As an example, let’s assign a simple dynamic integer property named “my_prop” to the currently active object and set its value to 55.
To do this, execute this simplest code:
|
1 |
bpy.context.object['my_prop'] = 55 |
We can check that the property was successfully assigned to the object.
|
1 2 3 |
print('my_prop:', bpy.context.object['my_prop']) # my_prop: 55 |
Let’s create a custom panel in the 3D viewport area named “TEST” and display the assigned property on it.
|
1 2 3 4 5 6 7 8 9 |
class TEST_PT_panel(bpy.types.Panel): bl_idname = 'TEST_PT_panel' bl_label = 'TEST PANEL' bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = 'TEST' def draw(self, context): self.layout.prop(bpy.context.object, '["my_prop"]') |
After registering the panel in the Blender Python API,
|
1 |
bpy.utils.register_class(TEST_PT_panel) |
it will appear in the viewport panels tabs.
Now we can quickly change the value of the “my_prop” property by simply editing it in the field on our panel.
We can assign any value to the property now. But what if we want to limit the range of possible values for the property, for example, from 0 to 100?
This can be done through the “id_properties_ui” object (bpy.types.IDPropertyUIManager), which is designed specifically for managing dynamic properties via the UI.
Let’s create such a management object for our property:
|
1 2 3 |
ui = bpy.context.object.id_properties_ui('my_prop') # <bpy id prop ui manager: name="my_prop", address=0x00000238280787E0> |
Now, with its help, we can manage our simple dynamic object property as easily as its regular properties.
Assign a description to our property (displayed when hovering over it), and the minimum and maximum possible values.
|
1 2 3 |
ui.update(description='My Custom Property') ui.update(min=0, soft_min=0) ui.update(max=100, soft_max=100) |
Now, if we try to set a value outside the specified range (0 to 100) in our property field on our panel, it won’t work. Also, if we scroll over our property field with the mouse and reach the limit, the value will be fixed at the minimum or maximum possible value within the specified range.
The specified description will also be displayed when we hover over our property field on the panel.

.blend file on Patreon