← ClaudeAtlas

drivers-and-app-handlerslisted

Drive properties from expressions or other properties via the Driver API, and react to scene events via the bpy.app.handlers callbacks. Covers driver_namespace for Python functions, the new exit_pre handler in 5.1, and the must-be-fast contract for any handler.
TMHSDigital/Blender-Developer-Tools · ★ 13 · API & Backend · score 66
Install: claude install-skill TMHSDigital/Blender-Developer-Tools
# Drivers and Application Handlers ## Trigger Use this skill when the user: - Wants property A to follow property B with some math (driver) - Asks about `driver_add`, `FCurve.driver`, `driver.expression`, `driver_namespace` - Wants to run code on file save, file load, frame change, depsgraph update, or process exit - Mentions `bpy.app.handlers`, `save_pre`, `load_post`, `depsgraph_update_post`, `exit_pre` - Has a driver expression that fails security checks because it tries to call a Python function This skill bundles two related "reactive" patterns. They show up together often (a driver that calls a function registered on a handler), so they share one skill. ## Part 1: Drivers ### What a driver is A driver replaces a static animation curve with a real-time-evaluated expression. It is attached to one property (the **target**) and reads zero or more other properties (the **variables**), then evaluates a string expression to compute the target's value on each frame. Concretely: an `FCurve` whose `.driver` field is set is a driver. The animation system evaluates `driver.expression` instead of sampling the curve. ### The Driver API ```python import bpy def add_simple_driver(obj, data_path, index, expression): """Attach a driver to obj.data_path[index] that evaluates `expression`. Returns the FCurve so the caller can add variables. """ fcurve = obj.driver_add(data_path, index) fcurve.driver.type = 'SCRIPTED' fcurve.driver.expression = expressio