I used the local coordinates of the armature
newbone.tail = arm.matrix_world.inverted() * o.location to create a bone between its parent and an empty as shown below:
import bpy scene = bpy.context.scene arm = bpy.data.objects['Armbvh'] newbonename = 'My_NewBoneMarker' bpy.ops.object.mode_set(mode='EDIT') newbone = arm.data.edit_bones.new(newbonename) parentbone = arm o = scene.objects.get(newbonename) newbone.tail = arm.matrix_world.inverted() * o.location if newbone.name != 'Origin': newbone.use_connect = True newbone.parent = arm.data.edit_bones['ParentBone'] newbone.head = arm.data.edit_bones['ParentBone'].tail bpy.ops.object.mode_set(mode='OBJECT')
The problem I'm facing is that the new bone is very big as shown below because the rest pose of the armature is at (0,0,0) so the newbone is created between the parentbone in edit mode and the empty which is a big distance as shown below. Any advice how to fix this? I want the bone to be created between the location of the bone in pose mode in frame 0 and the location of the empty as demonstrated below.
This is the problem in edit mode (rest position):
Problem in Pose position:
This is what I where I want the new bone to be created to have a length between the parent bone in pose mode and the empty as shown below: