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?

  • $\begingroup$ 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. $\endgroup$ – Mentalist Sep 8 '15 at 10:46
  • $\begingroup$ Thanks Mentalist for the reply. I am looking for python scripts for automation as you mentioned. Anyway thanks for the support. $\endgroup$ – 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")
  • $\begingroup$ 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? $\endgroup$ – Varun kumar Sep 8 '15 at 11:01
  • $\begingroup$ 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/… $\endgroup$ – batFINGER Sep 8 '15 at 11:21
  • $\begingroup$ 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. $\endgroup$ – zeffii Sep 8 '15 at 11:56
  • $\begingroup$ @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. $\endgroup$ – batFINGER Sep 8 '15 at 12:11

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.