1
$\begingroup$

I need to get bone's location in edit mode. Is it possible? I found this, but it only works when I choose armature. I need to get bone's location without activating any armatures.

bpy.context.object.data.bones["BoneName"].head_local
$\endgroup$

1 Answer 1

1
$\begingroup$

Find the bone in the armature in bpy.data rather than in bpy.context. The position of the head and the tail, relative to the parent are given as head and tail. The positions relative to the armature are given by head_local and tail_local:

import bpy

armature = bpy.data.armatures['Armature']
bone = armature.bones['Bone']
head = bone.head
tail = bone.tail
head_local = bone.head_local
tail_local = bone.tail_local

Substitute the name of the armature you want for 'Armature' in the first line and the name of the bone for 'Bone' in the second line.

If you want world coordinates you have to transform the bone's local coordinates based on the position of the armature in world space.

$\endgroup$
1
  • $\begingroup$ it works fine. Thank you! $\endgroup$
    – Yokomizo
    Jan 2, 2022 at 15:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .