Scripting: Armatures
Offical API-Doc Links:
Get a list by
armatures = [obj for obj in bpy.context.scene.objects if obj.type=="ARMATURE"]
Armature
Blender differs between edit bones and pose bones. Edit bones can only be changed in edit mode!
obj=armatures[0]
if not obj.data.is_editmode:
bpy.ops.object.mode_set(mode="EDIT") # first set edit mode!
print(len(obj.data.edit_bones)) # will show zero bones if not in edit mode!
for b in obj.data.edit_bones:
print(f"{b.name}")
Check pose bones like this
obj=armatures[0]
# all bones
for b in obj.data.bones:
print(b.name)
# get by name
if "nose" in obj.data.bones:
nose_bone = obj.data.bones["nose"]
# active
print(obj.data.bones.active)
# edit mode
print(obj.data.is_editmode) # True/False