Reading bone location and rotation with python?

I want to read the armature space location and rotation of an armature bone using python.
I’ve managed to get a reference to the bone using own.channels[‘bone’] but then I want to get useable data about the bone’s rotation and location. When I say useable, it means I want to be able to transfer that data to worldLocation and worldOrientation, or to be able to ray cast from that location.

Anyone have any ideas?

OK, I solved it myself.

It seems that .toEuler became .to_euler and no one told me :slight_smile:

cont = bge.logic.getCurrentController()
    own = cont.owner 
    bne = own.channels['head']
    loc = bne.pose_tail   
    pose = bne.pose_matrix
    head = [ob for ob in own.children if ob.get("head",False) ==True][0]
    head.localPosition = loc
    new_pose = pose.to_euler() 
    head.localOrientation = new_pose

This way you can do some of the following cool things:
Have a hat that can fall off when the character gets shot.
Have arrows that stick in a monster and move acurately in line with its animations.
have parts of a player or monster catch on fire, and the fire follows the character’s movements.
Have a character pick something up and put it down such as a book, lamp or other item.

My problem so far is that getting bone.pose_matrix gives me a 4x4 matrix which I’m not sure how to turn in to something I can feed to object.local/worldOrientation.

I think I’ve fixed the problem I was having with copying the world location, but orientation/rotation is still a problem.

EDIT: Check the first post for the solution.

Have you the solution to rotation?