Scripting Python dans Blender — API bpy, add-ons, automation, batch processing, création d'outils personnalisés, panels, operators, UI, pipeline et intégration.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Instruções da origem · Visualização somente leitura
name
blender-scripting-python
description
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