How to capture an event of value change via python?

What would be the best way to capture an event of value change of some property in blender.

In my case, I need to run an operator when an artist changes the scene.frame_start or scene.frame_end in the timeline editor. How can I do this via python?

I apologize if this is a total noob question.

Thank you so much!

See frame_change_pre and frame_change_post handlers.

https://docs.blender.org/api/current/bpy.app.handlers.html?highlight=frame_change_post#bpy.app.handlers.frame_change_post

Thank you so much for a suggestion Korchy.
This works great with scene.current_frame
I need exactly the same thing, but to work with the sliders that adjust the frame range for the scene.
Is it possible to attach the update function to scene.frame_start and Scene.frame_end? Or perhaps I am missing a handler type that would allow me to capture the change of value in the frame range properties.

You can try to use the depsgraph_update_post handler to check the updation of all the scene and control the required parameters through this handler.

1 Like

Thank you so much Korchy! I think I got it to work!

You can use the propery callbacks

https://docs.blender.org/api/current/bpy.props.html

That will only work for properties created by your own addon, not existing ones created by Blender.
For existing properties, it’s apparently possible to subscribe to a message bus:

https://developer.blender.org/P563

He can create a custom property then use that to drive the actual frame range.

Thank you so much for all the responses. They are super helpful and I really appreciate your help!

In my specific case I will need the actual timeline frame range properties to drive other things in my code, including some custom properties. But also I would need the custom properties that might be changed to drive the frame range properties. So in a way I need a mechanisms to work both directions.

So as far as I understand I can only add update functions to custom properties and for the existing Blender properties I would need to explore the message bus.

The handler depsgraph_update_post kind of works as well, but I am worried about the overhead, because it would run every time some value is changed on any property, if I understand correctly.

The most trivial example of the functionality I am looking for is to print in the console “Hello World” every time frame range values are adjusted on the timeline editor.

Thanks again for your help!