import bpy
ob = bpy.data.objects
child = ob['cube']
parent = ob['armature']
bone = parent.pose.bones['bone']
child.parent = parent
child.parent_type = 'BONE'
child.parent_bone = bone
I wrote the script above to carry out bone parenting with Python.
The parenting setting works correctly, but at the end, the child object's transformation will have an offset.
How can I achieve bone parenting without offset?
Additional questions about batFINGER's answers.
I tested the script. But I still get the offset. Did I make a mistake?
I recorded two GIF to clarify the question.
In the case of the parenting using operator, the cube's transform is maintained, but in the case of parenting using script, the cube's transform changed.
- After creating an armature, change the bone transforms in pose mode.
- Operate bone parenting with cube & bone of armature.
- The ops method keeps the cube in place, but the script method changes the cube by the bone transform
- I want to achieve ops result using python script.



