Simplest way to drive a pose bone's global location When you drive a pose bone's location, you're actually driving its local, rather than global location (I guess that's true for any location, but still worth mentioning).

I've been trying to find the easiest way to drive the global location.
I already know I can find the global location using either of these methods:

poseBone.matrix.to_translation()
armature.matrix_world * pb.matrix * pb.location


So I thought that I'll write a custom driver function that will find the global location and drive the local location values according to a converting back from global-to-local.

But I can't seem to convert the global value back to the original local value. I tried:

armature.matrix_world.inverted() * pb.matrix.inverted() * globalLoc


And just:

pb.matrix.inverted() * globalLoc


But I could not get that original local value back. Since the order of these mutliplications is important, I tried to re-order the multiplicated variables in any arrangement possible but no luck.

I'm open to other methods for achieving this or any suggestions on how to solve it this way.
I already know I can find the global location using either of these methods:


Both will not give you the correct global matrix. The first lacks the armature object transformation and the second is twice multiplying the pose_bone location - it's in pb.matrix already. So the way to get global location is:

pbone_global_loc = (armature.matrix_world * pbone.matrix).to_translation()

And the way to get the pbone matrix back is:

pbone.matrix = armature.matrix_world.inverted() * pbone_global_loc

If the pbone_global_loc is 3x3 make it 4x4 with:

pbone_global_loc.to_4x4()