Kamil
Kamil

Reputation: 123

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')")

Upvotes: 5

Views: 2240

Answers (1)

keltar
keltar

Reputation: 18409

Use layout's operator_context field:

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

Upvotes: 8

Related Questions