I have a CollectionProperty
which contains an EnumProperty
, and I need to programatically assign each EnumProperty
's items
attribute.
You can assign a value to something like IntProperty
, BoolProperty
, StringProperty
etc.:
class Item(bpy.types.PropertyGroup):
asdf = bpy.props.StringProperty()
bpy.utils.register_class(Item)
bpy.types.Scene.collection = bpy.props.CollectionProperty(type = Item)
# create a new item, assign its properties
item = bpy.context.scene.collection.add()
item.asdf = "asdf"
, but my siduation with EnumProperty
is different here. The items
attribute is taken in through an argument:
class Item(bpy.types.PropertyGroup):
asdf = bpy.props.EnumProperty(
# items argument required to initialize, just filled with empty values
items = [
("", "", "")
]
)
bpy.utils.register_class(Item)
bpy.types.Scene.collection = bpy.props.CollectionProperty(type = Item)
# create a new item, assign its properties
item = bpy.context.scene.collection.add()
item.asdf = [
("asdf", "asdf", "asdf")
]
So when you assign a value, you're just changing whatever the active enum value is. And it gets mad at you for trying to assign an array of tuples to a string.
The (best?) way to dynamically assign items appears to just be to delete it, and then re-assign it.
This works with a normal EnumProperty
:
del bpy.types.Scene.collection
bpy.types.Scene.collection = bpy.props.EnumProperty(
items = [
("asdf", "asdf", "asdf")
]
)
, but it works differently when its part of a collection...
Calling the collection through bpy.types.Scene.collection
returns a tuple, and attempting to execute del bpy.types.Scene.collection[0]
throws AttributeError: 'builtin_function_or_method' object has no attribute 'asdf'
.
How can I assign my own values to the EnumProperty
s' items when they're in a CollectionProperty
?
I'm definitely open to the possibility that I'm coming at this the wrong way, I've been getting acquainted with BPY for the past couple days and all the jargon's making my head spin a bit.