0
$\begingroup$

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?

enter image description here

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.

enter image description here

$\endgroup$
5
  • $\begingroup$ 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 $\endgroup$
    – batFINGER
    Jan 7, 2017 at 9:18
  • $\begingroup$ @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? $\endgroup$
    – Tak
    Jan 7, 2017 at 10:42
  • $\begingroup$ 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). $\endgroup$
    – batFINGER
    Jan 7, 2017 at 11:49
  • $\begingroup$ @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. $\endgroup$
    – Tak
    Jan 7, 2017 at 11:59
  • $\begingroup$ Your example is just the local x euler_rotation. Put together answer with what I think you want. Suggest adding that image to q. $\endgroup$
    – batFINGER
    Jan 7, 2017 at 12:19

1 Answer 1

1
$\begingroup$

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")

v1 = pb1.head - pb1.tail
v2 = pb2.head - pb2.tail

if pb1 and pb2:
    print(degrees(v1.angle(v2)))
else:
    print("Invalid bone name(s)")
$\endgroup$
2
  • $\begingroup$ thank you so much, that did it. So if I wanted to set the limit of a joint angle with degrees angle around each axis let's say setting the joint angle between Bone and Bone.001 to be min -30 to +30 around every axis, Is using the limit_rotation constraint the correct way to do that? $\endgroup$
    – Tak
    Jan 7, 2017 at 12:27
  • $\begingroup$ You will probably need to use the IK to set limits on the joint angles. $\endgroup$
    – Mo Hossny
    Jan 16, 2018 at 9:49

You must log in to answer this question.

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