Parenting meshes to bones

Hello everyone,
I stumbled upon the following problem:
Whenever I parent a mesh to a bone like this:

mesh = bpy.context.active_object
mesh.parent =['myArmature']
mesh.parent_type = 'BONE'
mesh.parent_bone =['myArmature']

the mesh’s local transformation matrix is interpreted with respect to the bone’s transformation matrix (in world coordinates) after parenting which leads to the mesh “jumping” to its parent bone’s position and orientation.

However, I just want to link mesh and bone together so that whenever I move the bone, the mesh moves accordingly.
In terms of transformation matrices: At the moment of parenting, I want the tranformation matrix from bone to mesh to be kept and not to be overwritten by the local transformation matrix of the mesh.

Am I missing something here?
Any help would be greatly appreciated!

You’ll likely want to do something like this:

bpy.ops.armature.parent_set(type= ‘OFFSET’])

You’re talking about the operator described here, right?

I just gave it a shot. It only seems to be working for parenting bones to bones, not for parenting meshes to bones.

parent_bone expects a string, the bone name.

object.parent_bone = "hips"

Have object/s selected, armature active in pose mode, parent bone selected


Yes, that’s what I was referring to.

But, batFINGER is the expert here, so I’ll just let him talk.

Thank you very much, this is exactly what I was looking for!

Just a minor correction to your code. It’s


This thread can be marked as solved now! EDIT: Which I just found out I can do myself :wink: