After a lot of searching, I found out that a quick and dirty method to detect and execute code is by modifying one of the example scripts as in follows:
import bpy
class ModalTimerOperator(bpy.types.Operator):
'''Operator which runs its self from a timer.'''
bl_idname = "wm.modal_timer_operator"
bl_label = "Modal Timer Operator"
_timer = None
prev_frame = None
def modal(self, context, event):
if event.type == 'ESC':
return self.cancel()
if event.type == 'TIMER':
if self.prev_frame != bpy.context.scene.frame_current:
# Call your functions here <-----------
self.prev_frame = bpy.context.scene.frame_current
return {'PASS_THROUGH'}
def execute(self, context):
context.window_manager.modal_handler_add(self)
self._timer = context.window_manager.event_timer_add(0.1, context.window)
return {'RUNNING_MODAL'}
def cancel(self, context):
context.window_manager.event_timer_remove(self._timer)
return {'CANCELLED'}
def register():
bpy.utils.register_class(ModalTimerOperator)
def unregister():
bpy.utils.unregister_class(ModalTimerOperator)
if __name__ == "__main__":
register()
# test call
bpy.ops.wm.modal_timer_operator()