Let's say I have a mesh with an armature and I've given it an animation action. I know I can get the action with bpy.data.actions and the bones with bpy.context.selected_pose_bones. But how would I get only the bones that have keyframes set for that specific action? For example, let's say I make a kick action and only bones for the right leg have keyframes, no other bones have any for that action. How would I get the bones for the right leg given the kick action?


1 Answer 1


Following is one way of getting the bones in a given action.

armature = bpy.context.scene.objects['Armature']
action = bpy.data.actions['ArmatureAction.002']

pose_bones = set()

for fcurve in action.fcurves:
    pose_bone_path = fcurve.data_path.rpartition('.')[0]
    pose_bone = armature.path_resolve(pose_bone_path)

>>> pose_bones

Getting to the actual bone (that belongs to the data of the Armature) is accomplished like below

>>> bone = armature.data.bones[pose_bone.name]
>>> bone



You must log in to answer this question.

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