Pose Bone - Update Viewport Selection?

In pose mode – I am trying to have my script unselect all bones, then select a specific bone and ‘set inverse’ on its Child Of constraint.

bpy.data.objects["Armature"].data.bones['Bone.001'].select = True
bpy.ops.constraint.childof_set_inverse(constraint="Child Of", owner='BONE')

In this example, Bone.001 has the constraint and Bone does not.

The issue is it’s not truly selecting Bone.001. If I have Bone selected and run the script, Bone shows unselected and then Bone.001 turns green in the viewport. But if you look in the top left, it still shows Bone is selected. So the ‘set inverse’ part gives an error, since it’s trying to run the set inverse on Bone instead of Bone.001. I hope this makes sense, it’s really difficult to describe…


Is there a line I can use to ‘update’ the viewport?

From what I can see, you’re only selecting the bone, when you should also be setting the selected bone as the active bone.

import bpy
bpy.data.objects["Armature"].data.bones.active = bpy.data.objects["Armature"].data.bones["Bone.001"]
bpy.data.objects["Armature"].data.bones["Bone.001"].select = True
1 Like

That is some witchcraft right there :slight_smile:
Thanks for your help, I’m still very new to this but learning slowly!