How to create custom properties from dict.keys() within for loop

I have a long list of properties, each one with it’s own update function and I want to create them within a for loop because I’m a lazy person(who isn’t :slight_smile: ).

Here’s my code

# update functions would be defined above
prop_dict = {"prop_name0":update_fun0, "prop_name1":update_fun1}

for prop_name in prop_dict.keys():["MyObject"][prop_name] = 0
    bpy.types.Object[prop_name] = bpy.props.IntProperty(name=prop_name, default=50, update=prop_dict[prop_name]) # Here's where the error is thrown

Here’s the error message:

TypeError: 'bpy_struct_meta_idprop' object does not support item assignment

I’know it should rather be something like that :

bpy.types.Object.the_name_of_the_prop = bpy.props.IntProperty(...)

You can do something like this:

props = {
    'prop1': None,
    'prop2': 51,
    'prop3': 6.51,
    'prop4': [],
    'prop5': "string",

for key in props:
    setattr(bpy.types.Object, key, props.get(key))
1 Like

Thanks a lot :wink: