As you see I tried to move two bones, and they don’t end up at the same location. My guess is that I’m not grabbing the the right location vector. But I’m not quite sure how to do this.
To test: spawn an armature, extrude a bone and disconnect it. Also, add one empty. Then the script should work.
import bpy
<br>from bpy import context
<br>armature = "Armature"
<br>pose_bone = context.active_pose_bone
<br>obj_empty = bpy.data.objects["Empty"].location <br>tst = bpy.data.objects[armature].matrix_world.inverted() <br>loc = tst @ obj_empty
<br>bpy.data.objects[armature].pose.bones["Bone.001"].location = loc
<br>bpy.data.objects[armature].pose.bones["Bone"].location = loc<br><br>print(obj_empty) <br>print (loc) <br>print (tst) <br><br>
This is urgent for me so any help is highly appreciated. Thank you for reading!
Replies
https://docs.blender.org/api/2.79/bpy.types.PoseBone.html#bpy.types.PoseBone.head
Get the pose-space 'offset' vector from head to tail, reposition the head to 'loc' and the tail to 'loc + offset', is what I'd try.
I had to look in the API docs to see any alternatives.
It seems boy.types.PoseBone.matrix is the pose-space matrix with constraints already applied, so any changes happen after the contribution of any constraints.
Try replacing the 'matrix' usage with 'matrix_channel', a different attribute:
https://docs.blender.org/api/2.79/bpy.types.PoseBone.html#bpy.types.PoseBone.matrix_channel