0
$\begingroup$

In my register I create the following property:

setattr(bpy.types.Scene, "test_enum", bpy.props.EnumProperty(items=items, update=func1))

and in func1 i have:

def func1(self, context: Context):
    scene = bpy.types.Scene
    value = getattr(context.scene, "test_enum")
    if value == 1:
        setattr(scene, "my_string", bpy.props.StringProperty(name="Enter Text"))

In the above code im trying to figure out how to grab "test_enum" dynamically, as opposed to hard coding it. Blender knows which property is being changed, how can I?

As a bonus question...is there any way for me to pass something to that func1?

$\endgroup$
2
  • 1
    $\begingroup$ Not an exact answer I think but this should help you. blender.stackexchange.com/a/255504/86891 $\endgroup$
    – Gorgious
    Jun 27 at 15:44
  • 1
    $\begingroup$ Come to think of it the linked answer should solve your problem. Use update=lambda self, context: func1(self, context, "test_enum") and then def func1(self, context, prop_name): value = getattr(self, prop_name) $\endgroup$
    – Gorgious
    Jun 27 at 15:49

1 Answer 1

0
$\begingroup$

Ended up solving this but thank you for the responses!

I created a wrapper function, though a lambda function would have worked as well (I've used that previously elsewhere and should have done that here earlier). Here is the implementation I went with:

setattr(bpy.types.Scene, "test_enum", bpy.props.EnumProperty(items=items, update=wrapper("test_enum"))

def func1(where_from):
    scene = bpy.types.Scene
    value = getattr(context.scene, where_from)
    if value == 1:
        setattr(scene, "my_string", bpy.props.StringProperty(name="Enter Text"))


def wrapper(where_from):
    def inner(self, context):
        return func1(where_from, self, context)

    return inner
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.