Application Handlers (bpy.app.handlers)¶
This module contains callback lists
Basic Handler Example¶
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)
Persistent Handler Example¶
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 add-on 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)
-
bpy.app.handlers.
frame_change_post
¶ on frame change for playback and rendering (after)
-
bpy.app.handlers.
frame_change_pre
¶ on frame change for playback and rendering (before)
-
bpy.app.handlers.
game_post
¶ on ending the game engine
-
bpy.app.handlers.
game_pre
¶ on starting the game engine
-
bpy.app.handlers.
load_post
¶ on loading a new blend file (after)
-
bpy.app.handlers.
load_pre
¶ on loading a new blend file (before)
-
bpy.app.handlers.
redo_post
¶ on loading a redo step (after)
-
bpy.app.handlers.
redo_pre
¶ on loading a redo step (before)
-
bpy.app.handlers.
render_cancel
¶ on canceling a render job
-
bpy.app.handlers.
render_complete
¶ on completion of render job
-
bpy.app.handlers.
render_init
¶ on initialization of a render job
-
bpy.app.handlers.
render_post
¶ on render (after)
-
bpy.app.handlers.
render_pre
¶ on render (before)
-
bpy.app.handlers.
render_stats
¶ on printing render statistics
-
bpy.app.handlers.
render_write
¶ on writing a render frame (directly after the frame is written)
-
bpy.app.handlers.
save_post
¶ on saving a blend file (after)
-
bpy.app.handlers.
save_pre
¶ on saving a blend file (before)
-
bpy.app.handlers.
scene_update_post
¶ on every scene data update. Does not imply that anything changed in the scene, just that the dependency graph was reevaluated, and the scene was possibly updated by Blender’s animation system.
-
bpy.app.handlers.
scene_update_pre
¶ on every scene data update. Does not imply that anything changed in the scene, just that the dependency graph is about to be reevaluated, and the scene is about to be updated by Blender’s animation system.
-
bpy.app.handlers.
undo_post
¶ on loading an undo step (after)
-
bpy.app.handlers.
undo_pre
¶ on loading an undo step (before)
-
bpy.app.handlers.
version_update
¶ on ending the versioning code
-
bpy.app.handlers.
persistent
¶ Function decorator for callback functions not to be removed when loading new files