1
$\begingroup$

Let's say I've created a scene property named a:

bpy.types.Scene.a = bpy.props.IntVectorProperty(
    name='a',
    description="Frequencies",
    size=2,
    default=[1, 2]
)

And now I would like to update it's size to something else.

  • How can I do that?
  • Do I have to override the property? What if instead of a single property I have a PropertyGroup and I want to update an IntVectorProperty that belongs to the group?
$\endgroup$

2 Answers 2

0
$\begingroup$

Have you seen Property Definitions? IntVectorProperty have other parameters to define, among which no "size"!

You can create a Custom property from PropertyGroup:

class CustomProperty(bpy.types.PropertyGroup):
    name: bpy.props.StringProperty(name="Name", default="Some name")
    description: bpy.props.StringProperty(name="Description", default="Frequencies")
    size: bpy.props.IntProperty(name="Size", default=2)

To update any property just assign some value:

bpy.types.Scene.a = 3
$\endgroup$
2
  • $\begingroup$ RUben: I don't think you read the question. Also your first statement is wrong, IntVectorProperty's do have size, which defaults to 3. Read carefully the link you shared :) Also I don't see how the rest of your answer addresses my question, I know how to create IntVectorProperty's, I just don't know how to change them dynamically to have different sizes. I want to have the same experience we have with list's in Python. Anyway, I appreciate the time you took to try and answer, but please fix your answer, that would be great :) $\endgroup$
    – gmagno
    Sep 11, 2019 at 17:21
  • $\begingroup$ my mistake - part of the parameters in manual is hidden behind the scroll $\endgroup$
    – RUben
    Sep 12, 2019 at 8:28
0
$\begingroup$
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)

$\endgroup$
1
  • $\begingroup$ If you also want to delete the VectorProperty from the context add exec("del bpy.context.scene['%s']" % bpy.context.scene.MyCollection[index].address.split(".")[-1] under each exec("del bpy.types.Scene.%s" % bpy.context.scene.MyCollection[index].address.split(".")[-1]) $\endgroup$ Aug 7, 2020 at 20:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .