Dev:Py/Scripts/Cookbook/Rigging/Add armature

提供: wiki
移動先: 案内検索

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:

  1. Access to Blender data you need always: import bpy
  2. because of rotating the bones later pi = 3.14.... is needed and imported from math
  3. creation of of a new armature (look what bpy.ops.object can do too!)
  4. standard way of getting a variable pointing to a just created object
  5. remove the # before ob.name and replace the string by what you would like!
  6. to access the bones you need a link to the new created objects data
  7. extrusion needs edit-mode so set it!
  8. create by extrusion 3 more bones! bone length is adjusted too
  9. 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)
  10. but maybe you could give the bones already nicer names? e.g.: eb.name = "test_" + str(i)
  11. finish by going back to object-mode