blender_execute_python
Execute custom Python in Blender to automate node graphs, drivers, rigging, bmesh operations, and more, returning output or tracebacks.
Instructions
Execute arbitrary Python inside Blender and return stdout, the expression value, or the traceback.
This is the general escape hatch: use it for anything the dedicated tools do not cover (node graphs, drivers, custom rigging, numpy-style math, bmesh work). Available names: bpy, bmesh, math, mathutils (Vector/Euler/Matrix/ Quaternion), json, os, sys, random, time, view3d (a context manager that injects a 3D viewport area so bpy.ops viewport calls work).
Example:
python import bmesh bm = bmesh.new() bmesh.ops.create_cube(bm, size=2) me = bpy.data.meshes.new("C") bm.to_mesh(me) ob = bpy.data.objects.new("C", me) bpy.context.scene.collection.objects.link(ob) Result(ob.name)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Python source. A single expression returns its value; statements run as a script. Runs on Blender's main thread. | |
| capture_output | No | ||
| response_format | No | 'markdown' for readable output, 'json' for raw structured data. | markdown |