1
$\begingroup$

I'm writing an addon that generates a list of categories that I want to set in an enum property. The enum property is defined as such:

class PipelineProperties(bpy.types.PropertyGroup):
    asset_categories = bpy.props.EnumProperty(
        name="Asset Categories",
        description="Categories for Project Specific Assets",
        items=[
            ('init', 'init', 'test', 0)
        ]
    )


def register():
    bpy.types.Scene.pipe = bpy.props.PointerProperty(name='Pipeline Properties', type=PipelineProperties)
    bpy.utils.register_module(__name__)

def unregister():
    bpy.utils.unregister_module(__name__)
    del bpy.types.Scene.pipe

The enum property is accessed by:

bpy.context.scene.pipe.asset_categories

Here is the code where I assign a new value to this enum property:

scn = bpy.context.scene
scn.pipe.asset_categories = bpy.props.EnumProperty(
            name='Asset Categories',
            description='Testing',
            items=[('new', 'new', 'test value', 0)]
        )

Here is the error message:

scn.pipe.asset_categories = bpy.props.EnumProperty(as_name_list)
TypeError: bpy_struct: item.attr = val: expected a string enum, not tuple

What is this error and why am I getting it? How would I go about setting the value of the enum property I have defined to something else?

$\endgroup$
0

1 Answer 1

5
$\begingroup$

You are attempting to assign a property definition as a property value:

scn.pipe.asset_categories = bpy.props.EnumProperty(...)

Should be:

scn.pipe.asset_categories = 'new'

Or, if you actually want to change the definition, uou must manipulate the type instead of it's instance:

del bpy.types.Scene.pipe
bpy.types.Scene.pipe = bpy.props.EnumProperty(...)

Where ... are all the enum arguments

$\endgroup$
2
  • $\begingroup$ What if I have a long list of these different categories? Say for example 'new, blue, true', and I want the enum property to hold all of these new values? $\endgroup$
    – jay
    Apr 14, 2017 at 6:34
  • $\begingroup$ @lvxejay please ask a separate question for that (its not closely related to this one) $\endgroup$
    – ideasman42
    Apr 14, 2017 at 9:10

You must log in to answer this question.

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