6
$\begingroup$

I have a bone and I need to get the location of its head and tail. I know that I can search for the corresponding edit_bone, but this list is only filled in edit mode. Is there a way to get both locations from within pose mode?

$\endgroup$
  • $\begingroup$ That should not lead to the desired result. When switching to edit mode I only can get the edit bones which are in default pose but not at the actual pose I defined in pose mode. $\endgroup$ – Miguellissimo Aug 29 '14 at 21:56
4
$\begingroup$

This simple script will print to the console and move two Empties to the location of the active bone in pose mode (last selected).

import bpy
from bpy import context

armature = "Armature" # change this to the name of your armature 

tail = bpy.data.objects[armature].location + context.active_pose_bone.tail
head = bpy.data.objects[armature].location + context.active_pose_bone.head

print(tail, head)
bpy.data.objects['Empty.head'].location = head
bpy.data.objects['Empty.tail'].location = tail

You will need to have two empties in your scene and on a visible layer, named Empty.tail and Empty.head in order for lines 10 and 11 to work. If not comment out lines 10 and 11 with a #.

Lines 6 and 7 get the locations of the armature and the active bone's head and tail, then adds them together. bpy.data.objects[armature] accesses an object with the name specified in the variable armature. If your armature has a different name, change it in the variable defined on line 4.

Line 9 print(tail, head) just spits the two vectors to the console.

Lines 10 and 11 sets the location of the two named empties to the location of the head and tail of the bone. I found this way easier then copying numbers from the console.

Note that you need to be in pose mode for this to work. Also the armature can got be rotated or scaled in object mode.

$\endgroup$
1
$\begingroup$

A non-python way to get the bone's head and tail, is to use snapping.
Change the snapping type to Vertex with Ctrl Shift Tab. Turn snapping on with Shift Tab, or leave it off and hold Ctrl to toggle it on during movements. Then just snap a empty to the bones. While in pose mode, just select the empty then snap it to the bone you want. Then to get the coordinates just look at the empty's location. It is at the top of the Properties panel, press N to show it.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.