When working with a complex rig, it’s sometimes necessary to quickly find the topmost bone. Since all bones in the rig are linked using a parent-child relationship, we can write a simple script that will traverse the entire hierarchy, starting with the currently active bone, and find the topmost bone.
Let’s say we have a complex rig and one of its child bones is active.
For clarity, switch to edit mode. This will allow us to immediately see all selections in the rig hierarchy, and, we won’t need to update the state for the selected bones.
|
1 2 |
if bpy.context.mode != 'EDIT': bpy.ops.object.mode_set(mode='EDIT') |
Currently active rig armature.
|
1 2 3 |
armature = bpy.context.active_object.data # <bpy_struct, Armature("Armature") at 0x000001BA07396988> |
And the currently active bone on it.
|
1 2 3 |
active_bone = armature.edit_bones.active # <bpy_struct, EditBone("Bone.011") at 0x000001BA071B1618> |
All bones in the rig are connected in a parent-child relationship. Each bone contains a list of pointers to its child bones, as well as a pointer to its parent bone. This is what we need.
|
1 2 3 |
parent = active_bone.parent # <bpy_struct, EditBone("Bone.009") at 0x000001BA06EACB98> |
By creating a While loop on this pointer from the current bone to its parent, we can traverse up the rig to the topmost bone.
|
1 2 3 4 5 6 |
while active_bone.parent: active_bone = active_bone.parent print('step up: ', active_bone) active_bone.select = True active_bone.select_head = True active_bone.select_tail = True |
For clarity, we select each subsequent parent bone along the way.
After the loop completes, the active_bone pointer will contain a pointer to the topmost bone in the rig, the one without a parent bone.
|
1 2 3 |
print('topmost bone: ', active_bone) # topmost bone: <bpy_struct, EditBone("Bone") at 0x000001BA07322098> |
The topmost bone will also be selected.
If we simply want to find the topmost bone in the rig without selecting the entire path, we can omit the selection operations inside our While loop.

.blend file on Patreon