Blender Python scripting, safety audit and gotchas
blenderbpypythonsecurityrigging
.blend files can carry embedded Python (text datablocks registered as modules, plus
driver expressions) that runs when the file opens with auto-run enabled. Commercial or
community character rigs almost always ship such scripts for their UI panels. This article
covers how to audit them without running them, how to open a file trusted on a per-file
basis, and API traps met in Blender 5.x while scripting a purchased character rig (the
Pharah v5.3 model, August 2026).
Auditing embedded scripts without executing them
Run Blender headless, with factory settings and auto-exec disabled, and a dump script that writes out every text block and driver expression:
blender --background --factory-startup --disable-autoexec model.blend --python dump.py
dump.py iterates bpy.data.texts (write t.as_string() to files) and every
obj.animation_data.drivers / shape_keys.animation_data.drivers expression. Then grep
the dump for socket, urllib, requests, subprocess, os.system, eval, exec,
open( with write modes, and wm.url_open. In the Pharah case the 5,000-line rig script
was benign: UI panels, a driver helper, and user-clicked links to the author's site.
Opening a file trusted, per file
Do not turn on global "Auto Run Python Scripts". Instead open the vetted file with:
bpy.ops.wm.open_mainfile(filepath=path, use_scripts=True)
Hot-reloading a rig's UI script
A data-driven rig panel can be extended by editing its text datablock (for example adding entries to an outfit dictionary) and re-registering it in place:
txt = bpy.data.texts["PBGv5.py"]
ns = {"__name__": "reload"}
exec(compile(txt.as_string(), "PBGv5.py", "exec"), ns)
ns["register"]()
Blender tolerates re-registering classes with the same bl_idname, but app handlers
(such as load_post) get added twice; remove the duplicate afterward.
API gotchas (Blender 5)
mesh.materialsyieldsMaterialobjects directly;obj.material_slotsyields slots with a.materialattribute. Mixing them up raises AttributeError.- Custom
PropertyGroupclasses may not be reachable asbpy.types.<Name>attributes in Blender 5. Inspect them through an instance instead, for exampleobj.pharah_vars.bl_rna. - Setting a property that has an
update=callback from code runs the callback, exactly as the UI would. Use that path (for example setting an outfit index) instead of pokinghide_viewport/hide_renderdirectly, so dependent logic (morphs, visibility) stays consistent. mesh.vertices[i].cois the basis shape. It ignores shape-key morphs and armature pose, so geometry fitted to it floats or clips once the character is posed or morphed.- Objects hidden with
hide_viewportshow no monitor icon in the Outliner until the "Disable in Viewports" filter toggle is turned on. - Vertex groups named as masks may be inverse masks (nearly every vertex weighted); check the weights before using one as a selection.
Headless modeling for 3D printing
- Run scripts with no UI:
blender --background --python build.py -- <args>; everything after--is left for the script (sys.argv[sys.argv.index('--') + 1:]). - Build solids with bmesh and explicit coordinates, not
bpy.ops. A loop ofbpy.ops.mesh.primitive_*+ rotate +transform_applyproduced unrotated boxes and 2,733 non-manifold edges on a mower-wheel model (operators depend on context, active object and selection); the bmesh version had zero. Check manifoldness before exporting for a slicer. - STL in Blender 4.2+/5:
bpy.ops.wm.stl_exportandbpy.ops.wm.stl_import(the oldexport_mesh.stladd-on operator is gone). - SVG import keeps a logo's orientation correct; extrude the curve and convert to mesh for printing. Preview renders headless with Eevee (or Cycles on CPU) from a fixed camera.
- See Designing a printable replacement part from photos and calipers and Slicing from the command line with Bambu Studio (flatpak), including two-color prints.
See also
- Driving Blender from Claude with blender-mcp
- Making clothing for a rigged character by duplicating body faces
- Rendering stills and short films with headless Blender
Linked from
- Designing a printable replacement part from photos and calipers
- Driving Blender from Claude with blender-mcp
- Generating Trackmania 2020 maps with GBX.NET
- Making clothing for a rigged character by duplicating body faces
- Rendering stills and short films with headless Blender
- Slicing from the command line with Bambu Studio (flatpak), including two-color prints
- Visualizing Ezekiel 1 (the four living creatures and the wheels)