From BlenderWiki
Add Armature
Script
Run this from the Text editor.
import bpy from math import pi bpy.ops.object.armature_add() ob = bpy.context.scene.objects.active #ob.name ="give me a good name!" arm = ob.data bpy.ops.object.mode_set(mode='EDIT') for i in range(3): bpy.ops.armature.extrude() bpy.ops.transform.translate(value=(0.0, 0.0, 1.0)) for i in range(len(arm.edit_bones)): eb = arm.edit_bones[i] # eb.connected = True eb.roll = i*(20/180*pi) eb.tail[0] = eb.head[0] + 0.2*(i+1) bpy.ops.object.mode_set(mode='OBJECT')
Explanation
to be written
The important steps:
- Access to Blender data you need always: import bpy
- because of rotating the bones later pi = 3.14.... is needed and imported from math
- creation of of a new armature (look what bpy.ops.object can do too!)
- standard way of getting a variable pointing to a just created object
- remove the # before ob.name and replace the string by what you would like!
- to access the bones you need a link to the new created objects data
- extrusion needs edit-mode so set it!
- create by extrusion 3 more bones! bone length is adjusted too
- now do something with the all 4 bones! Removing the # before # eb.connected = True gives an error in the SVN of 3 oct 2011 (TODO?? remove)
- but maybe you could give the bones already nicer names? e.g.: eb.name = "test_" + str(i)
- finish by going back to object-mode