Skip to content

Custom properties

Sometimes it can be useful to be able to control certain values that you use in a script from the UI. The most flexible, but also most complex, approach would be write an add-on. This allows creation of a nice UI that fully integrates in Blender, but that approach can be quite a bit of work to create.

Fortunately, in quite a few cases there's a simpler alternative if all you need to control are simple Python values, like an int, float, string or list. From Python you can set custom properties on pretty much any Blender Python data block (see here for more details) and then access those values from the UI:

>>> o
bpy.data.objects['Cube']

>>> o['My prop'] = 123.4
>>> o['My 2nd prop'] = (1, 1, 0.5)

This actually works both ways: adding or editing a value from the UI will update the value(s) available through Python. For example, after adding a string value named A string value through the UI:

# New property
>>> o['A string value']
'hello!'

# Updated value
>>> o['My prop']
999.0

>>> list(o.keys())
['My prop', 'My 2nd prop', 'A string value']

One difference between creating properties through the UI versus through Python is how the limits on the property are initialized. When using the UI the default allowable range for ints and floats is 0 to 1 annoyingly (see image below), while for a property created through Python they are initialized to -inf to inf.

Custom properties are saved to the blend file, and will get copied along when duplicating an object having them set.

You can then use these values in a script, for example to control a number of objects to create, set a 3D coordinate, or to give certain objects specific roles. You can even animate the values of custom properties.

See this documentation page for a bit more detail.


Last update: 06 March 2024 19:57:26