# Global Pose/Rotation of a bone

Is it possible to determine the pose/rotation of a bone depending on the parent bones (with Python), in the best case in euler angles.

For example, I have a model of a human and the arm is rotated in such a way that the body forms a T-shape. Then the hand is rotated that the palm points in the same direction as the face.

Now I would like to determine which rotation I would have to perform only on the hand to obtain the same direction without moving the arm.

• I am not sure I understand your question in detail. You said the hand is rotated the same direction as the face, and then you ask what rotation you would need to perform only on the hand.? In any case, perhaps this question/answer helps: blender.stackexchange.com/questions/1283/… . Commented Nov 1, 2013 at 12:08
• I meant, if I first rotate the upper arm, then the forearm and finally the hand, I have to perform a different rotation as if I would only rotate the hand to point in the same direction. Commented Nov 1, 2013 at 13:13

If I understand you right, the bone shall have the same rotation as its parent (in pose mode):

To achieve this by script, all you basically need is the rotation part of the parent. Construct a 4x4 transformation matrix from the parent rotation and the target bone's translation and scale. Assign it to the bone's matrix property.

import bpy
from mathutils import Matrix

pbone = bpy.context.active_pose_bone
pbone_parent = pbone.parent

loc = Matrix.Translation(pbone.matrix.to_translation())

# Rotation only (strip location and scale)
# TODO: make it work for parent bones with negative scale too
rot = pbone_parent.matrix.to_euler().to_matrix().to_4x4()

s = pbone.matrix.to_scale()
scale = Matrix()
scale[0][0] = s[0]
scale[1][1] = s[1]
scale[2][2] = s[2]

mat = loc * rot * scale

pbone.matrix = mat

# Force redraw, so transform properties are immediately visible
for area in bpy.context.screen.areas:
if area.type == 'PROPERTIES':
area.tag_redraw()


Note that the script has issues with negative scaled parent bones, couldn't figure out how to do it properly.