Skip to main content
Became Hot Network Question
edited title
Link
Gorgious
  • 31.8k
  • 2
  • 49
  • 106

Adding How can I add a not hardcodedcustom property with a dynamically defined name attribute to an object?

Source Link

Adding a not hardcoded name attribute to an object

This works great:

bpy.types.Object.color_asd = bpy.props.FloatVectorProperty(
                subtype='COLOR',
            )

This errors:

UID_short = "asd"
bpy.types.Object[f"color_{UID_short}"] = bpy.props.FloatVectorProperty(
                subtype='COLOR',
            )

Error:

TypeError: 'bpy_struct_meta_idprop' object does not support item assignment

But the approach is wrong to begin with. Let's say I have 2 cubes, Cube and Cube.001 I then would like to create a custom property only for a specific object like: Cube.color_asd

And for Cube.001 for example Cube.001.color_mega

Like so:

name = f"color_{UID_short}"
obj[name] = bpy.props.FloatVectorProperty(
            subtype='COLOR',
        )

Which then errors with:

Error: Python: Traceback (most recent call last):
  File "C:\Users\bratp\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\Liebherr-Toolbox\material_panel.py", line 1037, in execute
    obj[name] = bpy.props.PointerProperty(type = ObjectCustomColors)
TypeError: invalid id-property type _PropertyDeferred not supported

I can't figure either issue out.