Hi.
I want to make a little improvement in my current workflow…
I need to apply an existing constraint (Copy Transform) in my chain of bones.
I have this script but it only applies the existing constraint to just 1 bone. Unfortunally all others bones keep with the constraint.
- If exist any way to select multiples bones and apply the existing constraint to all of them I would love to know.
This is my script
import bpy
armature_name = "Armature"
bone_names = ["temp-faixa-e-1.001", "temp-faixa-e-2.001", "temp-faixa-e-3.001",
"temp-faixa-e-4.001", "temp-faixa-e-5.001", "temp-faixa-e-6.001",
"temp-faixa-e-7.001",
"temp-faixa-d-1.001", "temp-faixa-d-2.001", "temp-faixa-d-3.001",
"temp-faixa-d-4.001", "temp-faixa-d-5.001", "temp-faixa-d-6.001",
"temp-faixa-d-7.001"]
armature_obj = bpy.data.objects.get(armature_name)
if armature_obj:
bpy.context.view_layer.objects.active = armature_obj
bpy.ops.object.mode_set(mode='POSE')
for bone_name in bone_names:
pose_bone = armature_obj.pose.bones.get(bone_name)
if pose_bone:
# Apply the existing "Copy Transforms" constraint
bpy.ops.constraint.apply({"object": armature_obj}, constraint="COPY_TRANSFORMS", owner='BONE', target=bone_name, frame=1)
print(f"Constraint applied to {bone_name} in {armature_name}.")
else:
print(f"Pose bone {bone_name} not found in {armature_name}.")
else:
print(f"Armature object {armature_name} not found.")
Thank you so much.