You will require two armature, one to copy the transformations from and one to copy the transformations to. I have named my armature respectively Armature1 and Armature2.
We can access them through the objects
collection inbpy.data
.
armatureFrom = bpy.data.objects['Armature1']
armatureTo = bpy.data.objects['Armature2']
Looping through lists or collections in python is done with a for
loop. The pose bones (which can have constraints are fields of the armature's pose
property.
for boneTo in armatureTo.pose.bones:
We can check for a corresponding bone in the armatureFrom
with the Blender API's get()
method, which works on all blender collections.
boneFrom = armatureFrom.pose.bones.get(boneTo.name)
if boneFrom == None:
continue
If you want to remove all constraints from the target bone you can loop through them and remove them with the remove()
method.
for con in boneTo.constraints:
boneTo.constraints.remove(con)
By hovering your mouse over Blender properties you can get their python tooltips. I did so with an existing copy transforms constraint and could find the names of the fields which we need to assign.
copy_con = boneTo.constraints.new('COPY_TRANSFORMS')
copy_con.target = armatureFrom
copy_con.subtarget = boneFrom.name
copy_con.target_space = 'POSE'
copy_con.owner_space = 'POSE'
The completed script is here. Paste it in a text editor area in Blender and press Run Script to run it. Make sure you replace the names of the armatures with the names of armatures present in your file. Also backup your work. There are some destructive thing going on, like removing all constraints.
import bpy
armatureFrom = bpy.data.objects['Armature1']
armatureTo = bpy.data.objects['Armature2']
for boneTo in armatureTo.pose.bones:
boneFrom = armatureFrom.pose.bones.get(boneTo.name)
if boneFrom == None:
continue
for con in boneTo.constraints:
boneTo.constraints.remove(con)
copy_con = boneTo.constraints.new('COPY_TRANSFORMS')
copy_con.target = armatureFrom
copy_con.subtarget = boneFrom.name
copy_con.target_space = 'POSE'
copy_con.owner_space = 'POSE'