From EDIT_MESH change something on EDIT_ARMATURE

While I am in mesh edit mode I would like to change bones in the bone edit context.

2021-02-22 09_27_06-Blender

I have tried to switch context mode and then call the operator three times, which is not great.

  • Call once to leave mesh edit and go to object mode, then select mesh, go to mesh edit mode.
  • Now in edit bone context, call once to do the operation.
  • Now in edit bone context, call again to go to mesh edit mode.
import bpy

armature =['Armature']
bone = armature.bones[0]
mesh =['Cube']

def change_position():
    c = bpy.context
    if c.mode != 'EDIT_MESH':
        print('you must be in mesh edit mode')
    # change position of bone
    import random
    bone.head[0] = random.uniform(-1,1)

Best way is to do this at once. Every hack is welcomed. :slight_smile: