Hi.
I have searched the forums a bit, I havnt found an answer yet.
Im trying to add an empty, then set the position based on the active pose bone orientation.
This code adds an empty, sets the position to the pose bone head location, then sets a relative position.
I think ive found a way to solve this, its wierd though it may work.
First I set the empties parent to the pose bone, set a new location, then cleared parent.
I can’t see why you need the orientation (=rotation) of a bone to set a location (=translation) on another object. Don’t you just want to place an empty in a different spot, or do you want to rotate it like the bone? With the empty’s up-axis in the direction of the bone (Y-axis)?
I wanted to add empties at the rest orientation of the pose bone, so when moving the bone in pose mode, I could check the distance between the bone tail, and the empties.
So I needed a way to set the location of the empties, based on the bone orientation.
After positioning the empties, I had to also reparent them to the parent bone.
import bpy
ob = bpy.context.object
assert ob.type == 'ARMATURE'
scene = bpy.context.scene
mat = ob.matrix_world
for bone in ob.data.bones:
empty = bpy.data.objects.new("Empty", None)
empty.parent = ob
empty.parent_type = 'BONE'
empty.parent_bone = bone.name
empty.matrix_world.translation = mat * bone.tail_local
scene.objects.link(empty)
scene.update()