Poor mans FramChange detection

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):
        self._timer = context.window_manager.event_timer_add(0.1, context.window)
        return {'RUNNING_MODAL'}

    def cancel(self, context):
        return {'CANCELLED'}

def register():

def unregister():

if __name__ == "__main__":

    # test call

Is there a list somewhere of all the events that one could poll in 2.57? Thanks

One thing you may run into with that approach is that when it comes time to render your animation, your script will crash. The reason your script might crash is because it relies upon the scene.context to operate. While this works fine from the GUI, but when Blender is rendering an animation the context is invalid and set to None. So your code will have no way to re-trigger itself in that situation.

Feel free to click on the link in my signature. I have coded a couple of variations on the frame change that will work with rendering.

Thanks Atom. Maybe I am lucky, I noticed when one executes the script with the text window open, all frames are rendered without problems. I have checked out your examples but I found them to be complicated, and I could not adapt them for my purposes. I did not want the GUI for example.

Blender emits other events and has timer objects, I think there might be a way there

Update: No crashes. over 100 frames , with or without the text window open. Is there a Blender dev that can shed some light on this matter?