Application Handlers (bpy.app.handlers)

This module contains callbacks

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 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)
bpy.app.handlers.frame_change_post

Callback list - on frame change for playback and rendering (after)

bpy.app.handlers.frame_change_pre

Callback list - on frame change for playback and rendering (before)

bpy.app.handlers.load_post

Callback list - on loading a new blend file (after)

bpy.app.handlers.load_pre

Callback list - on loading a new blend file (before)

bpy.app.handlers.render_cancel

Callback list - on cancelling a render job

bpy.app.handlers.render_complete

Callback list - on completion of render job

bpy.app.handlers.render_post

Callback list - on render (after)

bpy.app.handlers.render_pre

Callback list - on render (before)

bpy.app.handlers.render_stats

Callback list - on printing render statistics

bpy.app.handlers.save_post

Callback list - on saving a blend file (after)

bpy.app.handlers.save_pre

Callback list - on saving a blend file (before)

bpy.app.handlers.scene_update_post

Callback list - on updating the scenes data (after)

bpy.app.handlers.scene_update_pre

Callback list - on updating the scenes data (before)

bpy.app.handlers.persistent

Function decorator for callback functions not to be removed when loading new files

Table Of Contents

Previous topic

Application Data (bpy.app)

Next topic

Property Definitions (bpy.props)