Scripting Python dans Blender — API bpy, add-ons, automation, batch processing, création d'outils personnalisés, panels, operators, UI, pipeline et intégration.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Scripting Python dans Blender — API bpy, add-ons, automation, batch processing, création d'outils personnalisés, panels, operators, UI, pipeline et intégration.
Guide complet du scripting Python dans Blender : API bpy, bmesh,
création d'add-ons, automation, batch processing, panels, operators,
et pipeline d'intégration.
# Appliquer scale/rotation à tous les objetsimport bpy
for obj in bpy.context.scene.objects:
obj.select_set(True)
bpy.ops.object.transform_apply(location=False, rotation=True, scale=True)
# Exporter chaque objet individuellement en OBJimport bpy, os
out = "exports/"
os.makedirs(out, exist_ok=True)
for obj in bpy.data.objects:
bpy.context.view_layer.objects.active = obj
bpy.ops.object.select_all(action='DESELECT')
obj.select_set(True)
bpy.ops.wm.obj_export(filepath=f"{out}/{obj.name}.obj")
# Créer une animation de rotationimport bpy, math
obj = bpy.context.active_object
for frame inrange(0, 100):
bpy.context.scene.frame_set(frame)
obj.rotation_euler.z = frame * math.radians(3.6)
obj.keyframe_insert(data_path="rotation_euler", index=2)
Débogage
# Imprimer toutes les propriétés d'un objetfor prop indir(bpy.context.object):
ifnot prop.startswith('_'):
print(f"{prop}: {getattr(bpy.context.object, prop)}")
# Imprimer l'arborescence bpy.datafor collection in bpy.data.collections:
print(f"Collection: {collection.name}")
for obj in collection.objects:
print(f" {obj.name} ({obj.type})")
# Voir les opérateurs disponiblesprint([op for op indir(bpy.ops) ifnot op.startswith('_')])
# Voir les propriétés d'un operateurprint(bpy.ops.mesh.primitive_cube_add.get_rna().properties)
Pitfalls
bpy n'existe pas en dehors de Blender — tester avec blender --python
bpy.ops échoue en background — certains ops nécessitent un contexte (area)
Scale non uniforme + Modifier — object.scale = (1, 1, 1) avant modificateurs
BMesh non libéré — bm.free() ou fuite mémoire
Context incorrect — passer {'area': ...} ou utiliser override
Blender API changes — Python API change entre versions majeures
Redraw manuel — bpy.context.area.tag_redraw() après changement UI
Add-on non enregistré — bpy.utils.register_class() oublié
Voir Aussi
blender-modeling — Automatisation de modélisation
blender-animation — Scripts d'animation
blender-geometry-nodes — Scripts pour créer/modifier des GN