Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blender 3D python For Every pose bone add a constraint not working

        selected = bpy.context.selected_pose_bones
        for bone in selected:
            bpy.ops.pose.constraint_add(type='COPY_ROTATION')

every time i run this it the contstraints on the same pose bone not on all the pose bones.

does anyone know how to make it add a constraint on every selected pose bone .

like image 868
Raspberry Avatar asked Oct 15 '25 15:10

Raspberry


1 Answers

bpy.ops.pose.constraint_add() is an operator that only effects the active item, in this case a pose bone. While you are looping through the bones in the selection you aren't using the reference to each bone as you loop through.

Instead of using an operator you can manually create the constraints on each specific bone and adjust other parameters as you go.

for bone in bpy.context.selected_pose_bones:
    nc = bone.constraints.new(type='COPY_ROTATION')
    nc.target = bpy.data.objects['Armature']
    nc.subtarget = bone.parent
    nc.influence = 0.5
like image 189
sambler Avatar answered Oct 17 '25 08:10

sambler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!