Derivate a Pose Matrix from a World Matrix

I have 2 different armatures A and B, both many bones

1° I want to get the world Orientation of a X bone of A
2° I want to pose a Y bone of B so its World Oriented like the bone X

I managed to get 1° but for now, i can just do this and it’s not right since it has to integer or derivate (depends how we see it) all the parents behind

Y.rotation_quaternion = WM_of_X.to_quaternion()

I tried this too, but it - ofc - doesn’t work either.

Y.rotation_quaternion = A.matrix_world.inverted().to_quaternion() * WM_of_X.to_quaternion()

I cannot integrate all the orientation of parent bones :confused:

Help please, it’s so annoying

Please share an example .blend file with some script snippet you currently have.

sorry for late answer.

Its basically any armature with some bone extrusion. You can do it in 2 secs in Blender

So basically, to make it more simplier … I want to orient the head of a character in a certain direction … all I have is a matrix_world ( and so , world orientation of the head)

So how can I know/derivate the Pose/Local orientation of the head so it matches the world Orientation ?

It still would be better if you can provide a full example - example rig setup, example world matrix you’ve got and the bone that should use the matrix. So we would be on the same page.

If you have the world matrix for the bone, you can convert it to the local matrix using inverted object (armature) matrix and then assign it to the https://docs.blender.org/api/current/bpy.types.PoseBone.html#bpy.types.PoseBone.matrix.