1
$\begingroup$

I'm trying to programmatically create an armature and I've run into an issue. While creating a new armature is straight-forward enough (bpy.ops.object.armature_add()), there's no option in that function call to assign a custom name and the function itself doesn't return anything helpful in this regard. While getting the armature instance isn't too bad (albeit a bit fragile) thanks to new armatures being appended to the end of the bpy.data.armatures list, the same doesn't quite seem to be the case for the armature's object. Without a known name to access it by, I'm not sure how to programmatically get access to it in a reliable manner.

The only solution I've been able to dig up so far involved looping over all objects in the scene, checking their type to see if they're armatures and then checking their names to see if it's the desired armature. I feel like this might run into performance issues with a large scene with many objects...

Image showing distinction between the armature name and the object name for a rig

Is there an efficient way for me to get an armature's object?

Is there a direct access method like bpy.data.armatures[<armature name>].parent_object or something of that nature?

$\endgroup$
4
  • 2
    $\begingroup$ bpy.ops.object.armature_add() ;ob = bpy.context.object ;arm = ob.data ;print(ob, arm) $\endgroup$
    – X Y
    Commented Oct 14, 2023 at 4:10
  • $\begingroup$ Perfect! I thought it was strange I couldn't find a simple solution, Blender's far too well built for that to make sense $\endgroup$
    – Master Xed
    Commented Oct 14, 2023 at 4:15
  • $\begingroup$ operators (the ones called from bpy.ops) are designed to be called from UI, so they do not return anything besides the final status of the operator $\endgroup$ Commented Oct 14, 2023 at 10:58
  • $\begingroup$ Ah, that explains a lot, thanks $\endgroup$
    – Master Xed
    Commented Oct 16, 2023 at 22:09

0

You must log in to answer this question.

Browse other questions tagged .