6
$\begingroup$

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?

$\endgroup$
2
  • $\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, 2015 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$ Sep 8, 2015 at 11:04

2 Answers 2

10
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ Notably, this only works if you are not already in edit mode on the armature. Is that on purpose I wonder? $\endgroup$
    – TheLabCat
    Apr 9, 2023 at 21:54
3
$\begingroup$

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")
$\endgroup$
4
  • $\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$ Sep 8, 2015 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, 2015 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, 2015 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, 2015 at 12:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .