Many operators for pose bones (including those for constraints) rely on having an active bone to refer to. However, how do we set this?
The answer is simple, though perhaps non-obvious:
arm = bpy.data.armatures["MyArmature"]
arm.bones.active = posebone.bone
where posebone is a pointer to some bone you've obtained from "object.pose.bones"
That's it. Simple :)
Simple, sure... working, not quite...
ReplyDeleteWhen you try to use a posebone you get a;
TypeError: BPy_PropertyRNA - Attribute (setattr): ArmatureBones.active expected a Bone type
since armature.bones are Bone types.
And object.pose.bones doesn't have an 'active' attribute either.
What does work is setting the active bone using arm.bones.active = arm.bones['Bone'] (but doesn't update the 3dview properly).
Right, well I didn't say to use a posebone directly! Rather, I said posebone 'DOT' bone (posebone.bone), which gets the bone type as required.
ReplyDeleteThe version you give also works, but is a bit more verbose.
I guess that you could also do:
arm.bones.active = arm.bones[posebone.name] # :)
hey aligorth,
ReplyDeleteI'm able to select up and down in an armature of bones with
bpy.ops.armature.select_hierarchy(direction='PARENT')
But i can't figure out how to select the tip or tail of a bone.
any suggestions?
kesten