6
$\begingroup$

I'm trying to write a script that constructs a transformation from a bone to an object (for "attaching" objects to animated armatures in a game engine). I can easily find the currently selected bone to construct the transformation from, using bpy.context.selected_pose_bones, but I cannot find any way to find the armature that owns the bone (which I need in order to calculate relative locations).

Does anyone know how to do this?

$\endgroup$
5
$\begingroup$

You can use the id_data property for one of the selected bones (you only need one because it's not currently possible to select multiple bones from different armatures at the same time). It should be as simple as the following:

context.selected_pose_bones[0].id_data

If you want just the armature's name:

context.selected_pose_bones[0].id_data.name
|improve this answer|||||
$\endgroup$
2
$\begingroup$

There's also a specialized function if you have a mesh object:

>>> bpy.context.object.find_armature()
bpy.data.objects['Armature']
|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.