Search code examples
pythonoperatorsblender

Blender Python add operator to menu with invoke_default


I have created a simple menu in python where i can add operators to it like that

layout.operator("wm.center_object")
layout.operator("wm.move_camera")

the problem is that I need an operator to be called with INVOKE_DEFAULT.

The following is the line to call it immediately:

bpy.ops.object.custom_draw('INVOKE_DEFAULT')

and that works, but i cant figure out how to add the operator to my menu with INVOKE_DEFAULT because the following is not working:

layout.operator("object.custom_draw('INVOKE_DEFAULT')")

Solution

  • Use layout's operator_context field:

    layout.operator_context = "INVOKE_DEFAULT";
    layout.operator("object.custom_draw");