Accessing Bones of Armature without pre-selection in Python

Hey all.

I’m finishing a coding course, and I planned to do animation copy and export tools for Maya.
I have realised the Maya API/ dozen possible incomplete language APIs is hell.
So, I thought I’d give Blender a go. But, I am a total Blender Neewb.

Question:
I want to access the rotations/animation of an animated rig.
Copy them to a skeleton rig, for export into a game engine.

import bpy

sceneObjects = bpy.context.scene.objects

for obj in sceneObjects:
    if obj.type == "ARMATURE":

So, I can find an Object in the Scene of type ARMATURE, but the type or reference returned, doesn’t allow me to access the bones it contains.

I can see in the docs that there are structs such as ArmatureBones, and that Armature.bones allows access to the bones of any given armature.

How on Earth do I get from a context.scene.objects to being able to access the armature.bones?

Unless there’s a better way to copy animation from a full IK/FK/Bind animation rig to a Skeleton Rig without a name-compare loop?

Advice/Tips are very very welcome.

I believe you want obj.data.bones

1 Like