from bpy.props import CollectionProperty, IntVectorProperty, StringProperty
from bpy.types import AddonPreferences
classes = []
def CreatVectorProp(size, name, vectortyp):
exec("bpy.types.Scene.%sproperty_%s = %sProperty(size= size)" % (vectortyp.lower(), name, vectortyp))
return "bpy.context.scene.%sproperty_%s" %(vectortyp.lower(), name)
def AddNewElementToCollection():
new = bpy.context.scene.MyCollection.add()
new.address = CreatVectorProp(10, "MyIntVector", "IntVector")
new.otherprops = "other stuff"
def RemoveElementfromCollection(index):
exec("del bpy.types.Scene.%s" % bpy.context.scene.MyCollection[index].address.split(".")[-1])
bpy.context.scene.MyCollection.remove(index)
def UpdateVector(index, newsize):
exec("del bpy.types.Scene.%s" % bpy.context.scene.MyCollection[index].address.split(".")[-1])
bpy.context.scene.MyCollection[index].address = CreatVectorProp(newsize, "MyNewVector", "IntVector")
def AssignValues(index, values):
exec("%s = values" % bpy.context.scene.MyCollection[index].address)
def GetValues(index):
return eval(bpy.context.scene.MyCollection[index].address)
class MyProperty(bpy.types.PropertyGroup):
address : StringProperty()
otherprops : StringProperty()
classes.append(MyProperty)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.MyCollection = CollectionProperty(type= MyProperty)
def unregister():
for ele in bpy.context.scene.MyCollection:
exec("del bpy.types.Scene.%s" % ele.address.split(".")[-1])
del bpy.types.Scene.MyCollection
for cls in classes:
bpy.utils.unregister_class(cls)
Something like this should do the trick.
(Tested on version 2.83.3)