# Parenting bones with offset using the data modul

I’m having problems parenting bones with offset without using operators. I’m sure this could be done with matrix math but unfortunately i dont know how to do that. Can somone help?

Your question is a bit confusing.
Just “parenting bones with offset” without moving anything can be explained/done with this little code snipped:

``````# bpy.ops.object.mode_set(mode='EDIT')  # if needed

# example data:
armature = bpy.data.armatures['Armature']
parent_bone = armature.edit_bones['Parent']
child_bones = [
armature.edit_bones['Child'],
armature.edit_bones['Child.001'],
armature.edit_bones['Child.002'],
]

for bone in child_bones:
bone.use_connect = False  # disconnect means offset
bone.parent = parent_bone  # set new parent
``````

But you asked for “matrix math”. I assume you want to move bones to the location of an other bone and copy the rotation. For this you need to find the angle between the two vectors of the bones, rotate by that angle and move to other bone. Is this what you need?

For now i solved it by using a ‘ChildOf Constraint’, wich works somehow but still i like to know why this child bone starts flipping in ‘Pose Mode’. There are no constraints whatsoever on it that could overwrite its parent space. So my original thought was to fix the matrix of that bone by copying the transformation of the parent to it (That’s what the first post was about).

There seem to be specific cases were this is not true (see gif below)
This selected bone in the gif (kinda hard to see but its selected) is parent to a bbone chain and detemines the twist of the bbone chain. The selected bone itself is parented to the foot bone ( bone1.parent = bone2 ) and isnt connected as you can see. Changing to ‘Pose Mode’ causes the bone to flip and i can’t figure out why.

I feel like i miss some fundamental understanding of how parenting works in blender. It seems to differ from the Autodesk mainstream products that i 'm used to.

Can you provide a file with just the armature or the legs? It’s hard to tell from the image what is parented and connected to what, and how the bendy bone is set up.

Sure. I tried to keep the file size to a minimum so this is just the result what my script spits out so far. If you like to take a look at the script, let me know. I appreciate you help Daniel.

parent_problem.blend (1.2 MB)

Setting the roll of “foot.blend” to the same roll of the other foot bones (180° in this case) solves the issue. The reason seems to be the Copy Transforms constraint getting the transformation from “foot.ik”.

1 Like

Thanks you so much for this Daniel. And know i found the wrongdoer in my script as well. The problem is caused by a wrong argument i send to my calculate_roll function (‘GLOBAL_POS_Y’ instead of 'GLOBAL_NEG_Y). Never bothered to check the rolls afterwards, cause i was sure they were aligned perfectly on creation.

Again, thanks for your time to look into this. Have a nice day!

1 Like