0
$\begingroup$

I needed a script that selects all children of multiple bones in pose mode. I must admit that my solution was very clumsy but helped in a particular situation =D So now I wonder how to do it the right, more elegant way? (basically how would you select all children, of any amount of selected bones?) I've put a loop with the number greater than the number of possible children. (I knew that the number of children will always be lower than 15, so my loop always selected all. But it feels very wrong =D )

import bpy
it = 15

while it > 0:
bpy.ops.pose.select_hierarchy(direction='CHILD', extend=True)
it -= 1
$\endgroup$
1
  • $\begingroup$ Do you want just the immediate children of the selected bones, or do you also want the children of the children and so on? $\endgroup$ Jul 31, 2022 at 0:23

2 Answers 2

1
$\begingroup$

This script will select all child bones from parent bones that share the same name as the ones in the list variable PARENT_BONES, provided that the mode is POSE mode.

import bpy

ARMATURE = "metarig"
PARENT_BONES = ["upper_arm.L", "upper_arm.R"]

if bpy.context.mode == "POSE":
    for b in bpy.data.armatures[ARMATURE].bones:
        if b.name in PARENT_BONES:
            for c in b.children_recursive:
                c.select = True

enter image description here

If you'd like to automatically go into pose mode and get rid of the check mode line, replace the check mode line with bpy.ops.object.mode_set(mode="POSE") to go into pose mode, regardless of which mode it is.

$\endgroup$
0
$\begingroup$

this script worked for me

import bpy

armature = bpy.context.active_object
bone = armature.data.bones[bpy.context.active_bone.name]

children = []
for child in bone.children_recursive:
    children.append(child.name)

for child in children:
    armature.data.bones[child].select = True
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .