# Bone angle in python

I have an armature found in my .blend file here and I want to know the angles of the joints of my armature in degrees? I want to know how I can get the angle in degrees through python?

As shown below the bone angle is set to be 0,0,0 around x,y,z although the bone is bent, I don't know why?

Also if I rotated the selected bone 30 degrees around x by selecting the bone pressing R then X then 30, the transform menu angle around x is not 30 as shown below, I don't know why? I've tried this bpy.data.objects['MyRig'].pose.bones['Bone2'].rotation_euler but it doesn't give the same result as shown in the transform menu.

• The value for Transform Rotation is the local rotation. To rotate around local axis use r x x 30. The pose bone transforms are relative to the rest pose. ie all zeros for loc and rot, and 1 for scale and the pose will be the same as the rest pose – batFINGER Jan 7 '17 at 9:18
• @batFINGER thanks for the explanation. So if I wanted to get the elbow joint angle (Bone2) I'll do this bpy.data.objects['MyRig'].pose.bones['Bone2'].rotation_euler? I wonder how I can get the joint angle between two bones in degrees not relative to the rest pose as for example 35 degrees or something? – Tak Jan 7 '17 at 10:42
• Are you after the global angle between the two vectors made up of global locations of v = (pb.head - pb.tail) of pose bones? Could also achieve this by adding a rotation difference variable to a driver using the two bones and global transform. If so maybe change q title to "Global angle between pose bones in python" or something similar. btw all angles in blender are in radians. To convert to degrees use math.degrees(angle). – batFINGER Jan 7 '17 at 11:49
• @batFINGER I'm honestly not sure what is a "global angle", is it the angle in between two vectors in the world space? I've tried doing this math.degrees(bpy.data.objects['MyRig'].pose.bones['Bone2'].rotation_euler[0]) and this gives 2.1344341156289847e-06 so still it's not the one I want. Like as shown here pasteall.org/pic/index.php?id=110859 the angles would have a value more than zero. Do you know what I mean? I hope I'm explaining properly, like my aim is to get the angle between each bone and it's parent cause after that I will set a rotation limit on each axis for every bone. – Tak Jan 7 '17 at 11:59
• Your example is just the local x euler_rotation. Put together answer with what I think you want. Suggest adding that image to q. – batFINGER Jan 7 '17 at 12:19

Test code that equates the angle between the two bones. It doesn't take into account bone roll.

import bpy
from math import degrees

from bpy import context
arm = context.object

pb1 = arm.pose.bones.get("Bone")
pb2 = arm.pose.bones.get("Bone.001")