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$
$\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$– MentalistCommented 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$– Varun kumarCommented Sep 8, 2015 at 11:04
Add a comment
|
2 Answers
$\begingroup$
$\endgroup$
1
This also works
bpy.data.objects["Armature"].data.bones["Jaw"].select = True
-
$\begingroup$ Notably, this only works if you are not already in edit mode on the armature. Is that on purpose I wonder? $\endgroup$ Commented Apr 9, 2023 at 21:54
$\begingroup$
$\endgroup$
4
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$ Commented 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$ Commented Sep 8, 2015 at 11:21
-
$\begingroup$ I think the
if jaw_bone is not None:
can be shortened toif jaw_bone:
because the .get either returns the object (and that evaluates always to a truthy value) or it returns None. $\endgroup$– zeffiiCommented 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$ Commented Sep 8, 2015 at 12:11