Blender Python add operator to menu with invoke_default

Question:

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')")
Asked By: Kamil

||

Answers:

Use layout’s operator_context field:

layout.operator_context = "INVOKE_DEFAULT";
layout.operator("object.custom_draw");
Answered By: keltar
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.