How can I dynamically add or remove properties in a class like this? I want to make a user interface where you can click on a button that will add new options and properties in that same user interface but for that I need a way to append new settings into this class.
import bpy
class MyPropertyGroup(bpy.types.PropertyGroup):
custom_1: bpy.props.FloatProperty(name="My Float")
custom_2: bpy.props.IntProperty(name="My Int")
bpy.utils.register_class(MyPropertyGroup)
bpy.types.Object.my_prop_grp = bpy.props.PointerProperty(type=MyPropertyGroup)
# test this worked
bpy.data.objects[0].my_prop_grp.custom_1 = 22.0
So how would I add a custom_3 property to this class for example?
MyPropertyGroup
inherit frombpy.types.PropertyGroup
. Thenbpy.types.Object.my_prop_grp = bpy.props.CollectionProperty(type = MyPropertyGroup)
then any object will have amy_prop_grp
and also have anadd
andremove
method. $\endgroup$bpy.props.CollectionProperty
would take one PropertyGroup (like custom_1, custom_2 in the example) and add() and remove() would just duplicate that in a list. You can't add another custom property likecustom_3
. $\endgroup$