0
$\begingroup$

I have a script that a adds a dropdown menu that I want to later animate the values of. In the update of the EnumProperty I update some visibility filters depending on the item selected which works fine when flipping through the items in the drop down, but when I animate the value and it changes that way the "update" doesn't get called. Can I make it so it does?

Here is an example script

import bpy


class MYOBJECT_PT_Panel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "My Object"
    bl_idname = "MYOBJECT_PT_Panel"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "My Object"

    def draw(self, context):
        self.layout.prop(context.scene, "MyObjectList")


def print_to_console(scene, context):
    print(context.scene.MyObjectList)


def register():
    bpy.types.Scene.MyObjectList = bpy.props.EnumProperty(
        name="My Objects",
        items=[(x, x, "") for x in ["A", "B", "C"]],
        update=print_to_console
    )
    
    bpy.utils.register_class(MYOBJECT_PT_Panel)


def unregister():
    bpy.utils.unregister_class(MYOBJECT_PT_Panel)
    del bpy.types.Scene.MyObjectList

if __name__ == "__main__":
    register()

Then go into animate and key the property and scrub the frames, you can see that the print state ment doesn't get called.

$\endgroup$
1
$\begingroup$

I achieved a similar functionality by adding a handler to bpy.app.handlers.frame_change_pre. This will make the print_to_console print every frame I can then check "is the gui displaying the same value as the previous frame", and if not it is animated on this frame.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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