Would anyone know how to do this?
Would anyone know how to do this?
This should be it…
‘obj’ is the armature object I guess? But armature objects don’t have a ‘pose’ property as far as I know.
And if it had the ‘pose’ property, would this code select the specific bone in blender? Wouldn’t it just instantiate the variable ‘pbase’ to the bone with name ‘Base’?
I think you misunderstood my question. I want to select a specific pose bone in blender so I can parent a previous selected object to this pose bone via the parent_set function.
A better formulation of the question:
How can I set a specific bone as the active_pose_bone?
What I showed allows you to grab a bone in pose mode and then operate on it.
If your after parenting bones in pose mode, then, I believe you can’t and need to do that in edit mode.
Or, if by your last comment, you just want to select some bones… Then as before, but then any of the following…
pbase.bone.select=True pbase.bone.select_tail=True pbase.bone.select_head=True
... >>> b.bone.select=True >>> bpy.ops.pose.select_flip_active()
from the select_flip_active API:
Activate the bone with a flipped name.
So this function activates the bone with a flipped name of the original active bone.
If I have an armature with bones: “Bone”, “Bone.001”, “Bone.002”, “Bone.003”. This function always makes “Bone” active, no matter what bone is selected.
So I still don’t know how to activate a specific bone
For the flipping to work in Blender, I believe that you need to give your bones unique names, but be consistent with the left and right sides of the armature.
The bone names on the left and right sides of the armature need to be exactly the same, but with the suffix “_L” and “_R”. I think you can use lowercase _l and _r instead, but need to be consistent.
eg. arm_upper_L, arm_upper_R, hand_L, hand_R, hip_L, hip_R.
I find that using the naming convention <limb><section><side> makes it easier to find the bones that I’m looking for in the alphebetised lists of bones in the dropdowns in various parts of the ui.
This way, all the arm bones are together, leg bones are together, etc.
Hmmm, teatime blunder, I see what you mean, I only tested on the root bone!
Yes, apperently there Isn’t a function (or I can’t find one) that lets you activate a specific bone.
The only functions I found that change the active bone:
Anybody else knows some more functions that changes the active bone?
I think I found It :D:
print("Bone selected: " + str(bpy.context.active_pose_bone.name)) bpy.data.objects["Armature"].data.bones.active = bpy.data.objects["Armature"].pose.bones['Bone.002'].bone print("Bone selected: " + str(bpy.context.active_pose_bone.name))
Output from code:
Bone before: Bone Bone after: Bone.002
Found the solution in this link
Its too bad scripting in blender 2.5 is so poorly documented that you gotta search a whole day before you find a solution to your problem
I did the following in Object Mode…
import bpy o=bpy.context.object b=o.data.bones['Bone.001'] b.select=True o.data.bones.active=b
But doesn’t need to be in Object mode, any mode will do.
As for the documentation, we’re building it now. But yes I find it easier to write a temporary slow function until I find the faster and easier internal one…
For those wondering why I wanted to select a specific bone: I am trying to write a script to automatically add armatures to certain .blend files.
I was trying to replicate the workflow you follow when you manually would add an armature and parent some objects to it. I wanted to use the parent_set function that you would normally call with ‘ctrl-P’ because this preserves the original orientation of the child object.
You can view my test script where I test the parenting here: http://pastie.org/2223811