I'm looking to get the local rotations of bones using Python, in other words given a parent and a child bone, the child bone's rotation off of the parent bone.

I saw this post:Get bone rotation in pose mode using Python

But I'm under the impression that this gives the world rotation? Any explanations are appreciated, thank you!



1 Answer 1


pose_bone.matrix is the transform from bone-local-space to armature-space (not world-space). It is the real transform, after constraints, drivers, etc. are applied.

So you can get the transform relative to the bone's parent by first transforming into armature space with pbone.matrix, then transforming from armature space in pbone.parent's space with pbone.parent.matrix.inverted().

for pbone in ob.pose.bones:
    m = pbone.matrix
    if pbone.parent:
        m = pbone.parent.matrix.inverted() @ m
    print(pbone.name, m)

Note that the matrix m might not be a pure rotation matrix in general (although for your screenshot it looks like it will be).

Also note that this won't work if you have non-invertible matrices. Avoid scaling bones to 0.


You must log in to answer this question.

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