1

I am creating a simple addon for Blender that handles easy animation changes between different actions. Everything works, but I am unable to find out properly how to catch if the user changes Start, Current, and End frame on Timeline, the same applies if the user changes Action in Action Editor (Dope Sheet).

enter image description here

I succeeded temporarily by using the poll function, but that is not an elegant solution at all. Moreover, it turned out that I cannot change some global vars I have added.

My second try was to add modal operator and catch all mouse clicks to refresh some data and that works to some degree, but I am still not satisfied with it.

Currently, I handle list view changes, so when it user clicks on other entry, say on Idle from Spawn I save states to Spawn (frame start, frame end, and current Action), then switch to Idle, check if the animation has Action assigned, and if not I create one then assign it (or saved one). So I have all states saved up to the current selection. If the user changes current_frame I can handle it with bpy.app.handlers.frame_change_post as @Gorgious stated, but I can't update frame_start, frame_end & dope sheet Action until the user clicks again on some other element.

I'm using Blender 2.79.

What are my options here?

Izzy
  • 243
  • 3
  • 13
  • 1
    The frame_change_post and frame_change_pre handler can be used to execute a method when the frame changes. See : https://docs.blender.org/api/current/bpy.app.handlers.html For the Actions I don't think that you can unless you link a method to the depsgraph_update_post or depsgraph_update_pre and loop over all actions to see which one is selected. (Not really optimized though) – Gorgious Oct 23 '20 at 06:27
  • @Gorgious that's pretty awesome. Actually, I encountered this solution but discarded it because I thought it was a game engine related. Any idea for handling the start & end frame change? – Izzy Oct 25 '20 at 20:05
  • If you copy/paste the 1st example in the documentation, you can catch every time the user changes the frame using the timeline. Replace the print statement by your logic. Do you need more help on the subject ? – Gorgious Oct 26 '20 at 20:42
  • Yes, I know. But that handles frame_change. There is no frame_start_pre and frame_end_pre handler. I have updated my question also. – Izzy Oct 27 '20 at 11:51
  • 1
    a modal timer? or (but in 2.8+) message bus. – lemon Oct 27 '20 at 11:59
  • bpy.app.handlers.scene_update_pre (and post) are the pre 2.8 versions of handlers that get run a squizzilion times to catch events in. – batFINGER Oct 27 '20 at 12:08
  • 1
    @lemon drawback of running a constant modal timer is it restricts auto-save. A draw callback for relevant spaces eg https://blender.stackexchange.com/questions/113912/is-automatic-reload-from-disk-confirmation-in-text-editor-possible and https://blender.stackexchange.com/questions/160909/handle-vertex-property-changes-with-msgbus-subscribe-rna could offer another way to look for changes. – batFINGER Oct 27 '20 at 12:16
  • @batFINGER I tried that one also. Can be a solution but running something in a constant loop didn't seem like the best idea. – Izzy Oct 27 '20 at 17:26

0 Answers0