Dev talk:2.5/Py/Scripts/Cookbook/Code snippets/Armatures

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

Hallo, A little bit mor comfort?

Suggestion for roll

import bpy, mathutils
 
def createArmature(origin,rig,obj):
    # Create armature and object
    amt = bpy.data.armatures.new(rig)
    rig = bpy.data.objects.new(obj, amt)
    rig.location = origin
    rig.show_x_ray = True
    amt.show_names = True
    # Link object to scene
    scn = bpy.context.scene
    scn.objects.link(rig)
    scn.objects.active = rig
    scn.update()
 
    # Create bones
    bpy.ops.object.editmode_toggle()
#does not work???    bpy.ops.object.mode_set(mode='EDIT')
    base = amt.edit_bones.new('Base')
    base.head = (0,0,0)
    base.tail = (0,0,1)
 
    mid = amt.edit_bones.new('Mid')
    mid.head = (0,0,1)
    mid.tail = (0,0,2)
    mid.parent = base
    mid.use_connect = True
 
    tip = amt.edit_bones.new('Tip')
    tip.head = (0,0,2)
    tip.tail = (0,0,3)
    bpy.ops.object.editmode_toggle()

try:
    bpy.context.scene.objects['SrcRigOb']
except:        
    createArmature((0,0,0),'SrcRig','SrcRigOb')
    createArmature((0,1,0),'TgrRig','TrgRigOb')

def copyRolls(src, trg):
    rolls = {}
    print("start copyRolls") 
    bpy.context.scene.objects.active = src
    bpy.ops.object.mode_set(mode='EDIT')
    for eb in src.data.edit_bones:
        rolls[eb.name] = eb.roll
    bpy.ops.object.mode_set(mode='POSE')
    print("rolls = ", rolls)
 
    bpy.context.scene.objects.active = trg
    bpy.ops.object.mode_set(mode='EDIT')
    for eb in trg.data.edit_bones:
        oldRoll = eb.roll
        eb.roll = rolls[eb.name]
        print(eb.name, oldRoll, eb.roll)
    bpy.ops.object.mode_set(mode='POSE')
    return
 
objects = bpy.context.scene.objects
copyRolls(objects['SrcRigOb'], objects['TrgRigOb'])