/blender-developer-tools:operatorsfrom blender-developer-tools
Authors bpy.types.Operator classes for Blender addons: bl_idname naming, poll/invoke/execute/modal lifecycle, bl_options, and redo-panel properties.
Ships in blender-developer-tools. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Use this skill when the user:
bpy.types.Operatorbl_idname, bl_label, bl_options, "redo panel", "F6 panel", "operator props"bl_idname (mesh, object, scene, view3d, etc.)my_addon_action)CATEGORY_OT_name (MESH_OT_my_addon_action)import bpy
class MESH_OT_offset_along_normals(bpy.types.Operator):
bl_idname = "mesh.offset_along_normals"
bl_label = "Offset Along Normals"
bl_description = "Move every vertex of the active mesh a fixed distance along its normal"
bl_options = {'REGISTER', 'UNDO'}
distance: bpy.props.FloatProperty(
name="Distance",
description="How far to move each vertex",
default=0.5,
min=-100.0,
max=100.0,
unit='LENGTH',
)
@classmethod
def poll(cls, context):
obj = context.active_object
return obj is not None and obj.type == 'MESH' and obj.mode == 'OBJECT'
def execute(self, context):
obj = context.active_object
if obj is None:
self.report({'ERROR'}, "No active object")
return {'CANCELLED'}
# Operate on bpy.data, not bpy.ops, and in bulk: one foreach_get /
# foreach_set pair instead of a Python loop over mesh.vertices (rule
# use-foreach-set-for-bulk-data). See the mesh-editing-and-bmesh skill.
mesh = obj.data
n = len(mesh.vertices)
co = [0.0] * (n * 3)
nor = [0.0] * (n * 3)
mesh.vertices.foreach_get("co", co)
mesh.vertices.foreach_get("normal", nor)
d = self.distance
mesh.vertices.foreach_set("co", [c + k * d for c, k in zip(co, nor)])
mesh.update()
self.report({'INFO'}, f"Offset {n} vertices by {d:.3f}")
return {'FINISHED'}
| Method | Required | Called when | Returns |
|---|---|---|---|
poll(cls, context) | Optional | Every UI redraw to decide if the operator is enabled. Must be cheap. | True to enable, False or falsy to disable |
invoke(self, context, event) | Optional | The user triggers the operator interactively (button, menu, keymap). Default forwards to execute. | {'FINISHED'}, {'CANCELLED'}, {'PASS_THROUGH'}, {'RUNNING_MODAL'} |
execute(self, context) | Yes | The operator runs, either after invoke or directly via bpy.ops.mesh.offset_along_normals() | {'FINISHED'} or {'CANCELLED'} |
modal(self, context, event) | Optional | After invoke returns {'RUNNING_MODAL'}. Called for each event until you return {'FINISHED'} or {'CANCELLED'}. | Standard return set |
draw(self, context) | Optional | The redo panel after the operator runs. Defaults to drawing all properties. | None |
poll must be fastpoll runs on every UI redraw. Do not iterate the scene, scan meshes, or call modifiers there. Restrict yourself to context.active_object, obj.type, obj.mode, and similar O(1) checks.
bl_options you almost always want'REGISTER': reports the operator in the Info editor and enables the Adjust Last Operation (redo) panel. Without it, properties cannot be tweaked after running. It does not add an undo step; that is 'UNDO'.'UNDO': hooks into the undo stack. Without this, your operator's effect cannot be undone with Ctrl-Z.'INTERNAL': hides the operator from operator search. Use for operators called only by other operators or panels. It still runs from Python and buttons.'BLOCKING': blocks anything else from using the cursor while the operator runs. Reserve for modal operators that need exclusive mouse input.'GRAB_CURSOR' and 'GRAB_CURSOR_X' / 'GRAB_CURSOR_Y': useful in modal operators to capture mouse motion.context.active_object returns None only when there is no active object:
read_factory_settings(use_empty=True), or a file whose view layer never had one.active_object=None deliberately.It is not None just because nothing is selected, and not just because Blender runs headless. Measured on 4.5.11 and 5.2.1 (--background --factory-startup): the startup scene's active object is Cube, and after bpy.ops.object.select_all(action='DESELECT') it is still Cube, with selected_objects == [] and Cube.select_get() == False.
Active and selected are independent. That is the real pitfall: an active object that is not selected, hidden, or not editable. A None guard does not catch it. Operators that act on the selection then run on nothing, or on the wrong set, without raising. Measured: bpy.ops.object.delete() with the Cube active but deselected returns {'CANCELLED'} and the Cube survives. When the operation needs selection, check obj.select_get() or work from context.selected_objects. Check obj.visible_get() before acting on what the user sees. Check obj.library is None (and obj.override_library if you edit overrides) before writing to linked data.
Always guard before dereferencing:
def execute(self, context):
obj = context.active_object
if obj is None:
self.report({'ERROR'}, "No active object")
return {'CANCELLED'}
if obj.type != 'MESH':
self.report({'ERROR'}, f"{obj.name} is a {obj.type}, expected MESH")
return {'CANCELLED'}
if not obj.select_get(): # active is not selected after a deselect-all
self.report({'ERROR'}, f"{obj.name} is active but not selected")
return {'CANCELLED'}
# ...
Even if poll already filtered, execute must re-check, because execute is also reachable from bpy.ops calls in scripts that bypass the UI.
Use self.report({level}, message) rather than print():
| Level | UI behavior |
|---|---|
'DEBUG' | Visible only in developer mode |
'INFO' | Status bar, info window |
'WARNING' | Status bar with yellow tint, info window |
'ERROR' | Status bar with red tint, info window |
'ERROR_INVALID_INPUT' | Same as ERROR but signals input was the cause |
Pair report({'ERROR'}, ...) with return {'CANCELLED'} so the operator does not appear successful.
import bpy
from mathutils import Vector
class OBJECT_OT_offset_active(bpy.types.Operator):
bl_idname = "object.offset_active"
bl_label = "Offset Active Object"
bl_options = {'REGISTER', 'UNDO'}
offset_x: bpy.props.FloatProperty(name="X", default=0.0, unit='LENGTH')
offset_y: bpy.props.FloatProperty(name="Y", default=0.0, unit='LENGTH')
offset_z: bpy.props.FloatProperty(name="Z", default=1.0, unit='LENGTH')
use_local: bpy.props.BoolProperty(
name="Local Axes",
description="Offset along object's local axes instead of world axes",
default=False,
)
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
obj = context.active_object
if obj is None:
return {'CANCELLED'}
offset = (self.offset_x, self.offset_y, self.offset_z)
if self.use_local:
# Column-normalize the basis so object scale does not distort the
# local-axis direction; to_3x3() alone carries scale into the result.
basis = obj.matrix_world.to_3x3().normalized()
obj.location += basis @ Vector(offset)
else:
obj.location.x += self.offset_x
obj.location.y += self.offset_y
obj.location.z += self.offset_z
return {'FINISHED'}
After running this operator from the menu, the user gets a redo panel in the bottom-left of the 3D viewport with sliders for offset_x/y/z and a use_local toggle. Adjusting them re-runs execute. This works only because 'REGISTER' is in bl_options and the properties are declared as annotations, not assignments (see the custom-properties skill).
Returning True / False from execute. The required return is the set {'FINISHED'} or {'CANCELLED'}. Returning a bool will raise.
Forgetting 'UNDO' in bl_options. The operator runs but the user cannot reverse it.
Slow poll that walks the scene, evaluates the depsgraph, or imports modules. Causes UI lag.
Properties as assignments:
# WRONG: the property is class-level data, not a typed annotation
class Bad(bpy.types.Operator):
distance = bpy.props.FloatProperty(default=0.5)
# RIGHT: annotation form, what 2.8+ requires
class Good(bpy.types.Operator):
distance: bpy.props.FloatProperty(default=0.5)
The assignment form silently does not register the property in some Blender versions and breaks the redo panel in all of them.
No bl_idname or a bl_idname without a category prefix (my_action instead of mesh.my_action). Blender requires the category.name shape.
Calling bpy.ops.<other> from execute for bulk work. Each bpy.ops call triggers a depsgraph evaluation. Operate directly on bpy.data or via bmesh instead. See the prefer-data-over-ops-in-loops rule.
addon-scaffolding for the registration pattern around your operator classcustom-properties for the annotation formmesh-editing-and-bmesh for what to do inside execute for mesh workprefer-data-over-ops-in-loopstype-annotate-props-and-defend-contextEach example runs headless, asserts the contract, and exits non-zero when it breaks. Run one with blender --background --python <script> --; pass a falsifier flag to watch the check fail.
prop-origin-transform: Street pedestal origin-to-base-center + data-API scale apply + matrix_parent_inverse for a flanged conduit elbow. Falsify: --skip-mpi (exit 8).temp-override-join: Join seven lantern parts into one object under bpy.context.temp_override — the supported replacement for the removed context.copy() dict-pass form. Falsify: --no-override (exit 3).timers-modal-threading: Proves the event-loop contracts behind long-running add-on work. Falsify: --windowed-background-child (exit 3).bpy.types.Operator: https://docs.blender.org/api/current/bpy.types.Operator.htmlWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub tmhsdigital/blender-developer-tools --plugin blender-developer-tools27 skills in this plugin
/addon-scaffoldingScaffold a Blender add-on as an Extensions Platform package: blender_manifest.toml, modular file layout, register_classes_factory, symmetric register/unregister. Use when the user starts a new add-on or extension, writes or fixes blender_manifest.toml, asks which layout or registration pattern to use on Blender 4.5 LTS or 5.x, or has classes that fail to register or unregister cleanly. Targets 5.2 LTS with 4.5 LTS fallback./ai-mesh-cleanupOrdered cleanup for an imported generated or scanned mesh before it goes to an engine: scene units, apply rotation and scale, origin to base, recalculate normals, evaluated triangle count, decimate to a budget, convex collider. Use when the user has a GLB, glTF or FBX that is not engine-ready, mentions unit scale, unapplied transforms, triangle budget, LODs or a collision hull, or is about to run mesh operations on an import without checking its scale. Targets 5.2 LTS with 4.5 LTS fallback./bake-high-to-lowCage-bake high-poly surface detail onto a low-poly target as a tangent-space normal map with bpy.ops.object.bake (Cycles, selected-to-active, active Image Texture node, UV layer, save_render). Use when the user wants a normal map from a dense mesh onto a game-resolution or decimated LOD, mentions cage_extrusion or use_selected_to_active, or gets a bake that returns CANCELLED, comes out black or flat, or fails with 'No active UV layer found'. Targets 5.2 LTS with 4.5 LTS fallback./blender-rulesBlender Python anti-pattern rules (bmesh leaks, bpy.ops in loops, deprecated context-copy overrides, bulk mesh writes, prop annotations and context guards, Extensions manifest, import scale, export modifiers, glTF/FBX axis RNA, the removed bgl module, the normals API removed in 4.1). Use when writing, reviewing or fixing any bpy / Blender add-on or script code./bl-info-migrationMigrate a legacy bl_info add-on to the Extensions Platform in three steps, with a before/after diff and the dual-format pattern. Use when the user has a bl_info dictionary in __init__.py, asks whether bl_info is deprecated or still supported, wants to publish to extensions.blender.org or ship an extension .zip, or sees warnings about legacy add-ons at install time. Targets 5.2 LTS; manifests work from 4.2./compositor-nodesBuild and render through the scene compositor from Python across the 4.5 LTS to 5.x split: scene.use_nodes plus scene.node_tree and a Composite node on 4.5, a CompositorNodeTree node group assigned to scene.compositing_node_group with interface sockets and a Group Output on 5.x, a Render Layers to Glare (Fog Glow) chain, the Glare node's move from enum properties to menu input sockets, and render.use_compositing. Use when the user scripts compositor nodes, adds bloom or glow, hits AttributeError on scene.node_tree in 5.x, sets glare_type or quality and gets AttributeError on 5.x, looks for the removed EEVEE use_bloom toggle, or renders and sees no compositor effect. Targets 5.2 LTS with 4.5 LTS fallback.Other plugins' skills for the same job