0
$\begingroup$

I'm writing a little picker for Blender. The principle of operation is simple. I select some armatures, go into pose mode. If I select bones, then bones with the same name in other armatures become selected.

import bpy

def picker(scene):
    selected_obj = [obj.name for obj in bpy.context.selected_objects]
    selected_arm = (bpy.data.armatures[selected_obj])
    selected_bones = [bone.name for bone in bpy.context.selected_pose_bones]
    for bone in selected_arm.bones:
        if bone.name in selected_bones:
            bone.select = True            
            
bpy.app.handlers.depsgraph_update_post.append(picker)

The script works if you specify the name of the armature, for example:

selected_arm = bpy.data.armatures['Armature.001']

But I don't know how to make it work for any number of armatures with any names.

$\endgroup$
1
$\begingroup$

I think this script should do what you want.

import bpy

armatures = [o for o in bpy.context.scene.objects if o.type == "ARMATURE"]
# If you want to select only from selected armatures, use the next line instead.
# armatures = [o for o in bpy.context.selected_objects if o.type == "ARMATURE"]
selected_bones = bpy.context.selected_pose_bones

for armature in armatures:
    for selected_bone in selected_bones:
        bone = armature.pose.bones.get(selected_bone.name)
        if bone:
            bone.bone.select = True
$\endgroup$
1
  • $\begingroup$ Thanks a lot! That's what I need! $\endgroup$ – AlexFrozd Jun 1 at 10:01
-1
$\begingroup$

I would iterate through all selected objects and check if their o.data was of type armature. Then, if it was, run the bone matching loop on it.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.