I have a lot of custom properties that use the same custom property class I've built to represent scientific notation. Within my register definition, I have to first register classes, and then individually add multiple instances of the same type of custom property. Is there a way to programmatically do this?

Current register method:

def register():
    for cls in classes:
    bpy.types.Scene.tools = bpy.props.PointerProperty(type=properties.ScientificNotation)
    bpy.types.Scene.anchors = bpy.props.PointerProperty(type=properties.ScientificNotation)
    bpy.types.Scene.cables = bpy.props.PointerProperty(type=properties.ScientificNotation)
    bpy.types.Scene.forces = bpy.props.PointerProperty(type=Properties.ScientificNotation)

Based on my interface, I may end up with 50 of these custom properties. Is there a way to create a "property factory" or add all these custom types to the Scene programmatically?

I didn't expect this to work, but trying to assign the property to a key like this:

bpy.types.Scene["tools"] = bpy.props.PointerProperty(type=properties.ScientificNotation)

yields TypeError: 'bpy_struct_meta_idprop' object does not support item assignment

I've found the types modules to be pretty inscrutable; it seems like you can't probe the Scene modules to see what customizations you've added to the interface, and I haven't been able to figure out how to get the "ID", which seems to be required for all of the methods for bpy.types.Scene.

  • $\begingroup$ Hello ! Probably not an answer to the question, but you may be interested in PropertyGroups if you're going to register a great number of custom props. $\endgroup$
    – Gorgious
    Jul 7 at 6:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.