bone orientation

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.

import bpy, math

pi = 3.1415926535897932384626433832795
pb = bpy.context.active_pose_bone
angle = 0.0
bone_loc = pb.bone.head_local

bpy.ops.object.mode_set(mode='EDIT')
br=bpy.context.active_bone.roll
bpy.ops.object.mode_set(mode='OBJECT')

bpy.ops.object.empty_add(type='PLAIN_AXES')
emp = bpy.context.active_object
emp.location=bone_loc

emp.location.x+=math.sin(angle)*pb.length
emp.location.z+=math.cos(angle)*pb.length

Though I can seem to find the correct bone orientation in bpy.

bpy.context.active_bone.matrix.to_euler() returned something that kind of look right, but the numbers didnt make sense after some tests.

Thanks for any help.

Heres an example file with the problem, run script to test.
http://www.pasteall.org/blend/31751

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.


bpy.ops.object.empty_add(type='PLAIN_AXES')
emp = bpy.context.active_object
emp.parent = bpy.data.objects['Armature']
emp.parent_type = 'BONE'
emp.parent_bone = 'Bone.001'
emp.location=(0,2.0,0)
bpy.ops.object.parent_clear(type='CLEAR_KEEP_TRANSFORM')

I dunno, maybe it will work.

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.

I released the script here.
Shape Key Drivers

It is as simple as this:

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

I will have to try that sometime.
Thanks for posting.