# How to get/select a bone by it's name in python?

I am having a master armature which has multiple bones. Now I want to apply rotation to a particular bone. Now, I can loop through all the bones in the armature and check for the bone with the expected name and then process it. But is there a way to select/get the bone object directly using it's name without looping through all the bones?

• Are you only interested in answers that involve Python? Because this can be done more easily in the Outliner if you don't need the process to be automated in a script. I can post an answer with screen shots if you like. – Mentalist Sep 8 '15 at 10:46
• Thanks Mentalist for the reply. I am looking for python scripts for automation as you mentioned. Anyway thanks for the support. – Varun kumar Sep 8 '15 at 11:04

This also works bpy.data.objects["Armature"].data.bones["Jaw"].select = True

Most collections in blender that you can iterate, where the items have a name property, can be accessed

item = collection["name"]
jaw_bone = obj.pose.bones["jaw"]


You can also use get, to avoid an error if an item of name doesn't exist

jaw_bone = obj.pose.bones.get("jaw")
if jaw_bone is not None:
print("Jaw bone exists")

• Thanks @batFINGER for the reply. I suspect this way of selection is based on pose mode? I found one more way of doing it. bpy.data.objects['Armature'].data.bones.get('Bone'). Can you tell me the difference of these ways of selection? – Varun kumar Sep 8 '15 at 11:01
• bpy.objects["Armature"].data = bpy.armatures["..."] which are the defined bones of the rig (rest position). The pose.bones collection on the armature object is for posing. Explained better here blenderartists.org/forum/… – batFINGER Sep 8 '15 at 11:21
• I think the if jaw_bone is not None: can be shortened to if jaw_bone: because the .get either returns the object (and that evaluates always to a truthy value) or it returns None. – zeffii Sep 8 '15 at 11:56
• @zeffi agreed. As an example it shows that it returns None if not defined, Could use collection.get("blah", False) as well, but that mixes objects and bools. Matter of preference I suppose. – batFINGER Sep 8 '15 at 12:11