This module contains callback lists
This script shows the most simple example of adding a handler.
import bpy
def my_handler(scene):
print("Frame Change", scene.frame_current)
bpy.app.handlers.frame_change_pre.append(my_handler)
By default handlers are freed when loading new files, in some cases you may wan’t the handler stay running across multiple files (when the handler is part of an addon for example).
For this the bpy.app.handlers.persistent decorator needs to be used.
import bpy
from bpy.app.handlers import persistent
@persistent
def load_handler(dummy):
print("Load Handler:", bpy.data.filepath)
bpy.app.handlers.load_post.append(load_handler)
on frame change for playback and rendering (after)
on frame change for playback and rendering (before)
on ending the game engine
on starting the game engine
on loading a new blend file (after)
on loading a new blend file (before)
on canceling a render job
on completion of render job
on initialization of a render job
on render (after)
on render (before)
on printing render statistics
on writing a render frame (directly after the frame is written)
on saving a blend file (after)
on saving a blend file (before)
on updating the scenes data (after)
on updating the scenes data (before)
on ending the versioning code
Function decorator for callback functions not to be removed when loading new files