# How to invoke a dialog from a menu?

More specifically - how to invoke a invoke_props_dialog from a bpy.types.Menu?

This is an operator that invokes a dialog:

import bpy

class MyDialog(bpy.types.Operator):

bl_idname = "tools.mydialog"
bl_label = "My Dialog"

string_prop = bpy.props.StringProperty(name="String Prop")

def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)

def execute(self, context):

return {'FINISHED'}

bpy.utils.register_class(MyDialog)

• It works from search as well as from menu, not sure what you mean? If it doesn't, the operation context might be changed in the particular menu you add the operator to. If so, create a layout subelement (row, column, split...) and set sub.operation_context = 'INVOKE_DEFAULT' above sub.operator(...). blender.org/documentation/blender_python_api_2_71_release/… – CodeManX Sep 22 '14 at 18:50

What about doing it like this ?

import bpy

class MyDialog(bpy.types.Operator):

bl_idname = "tools.mydialog"
bl_label = "My Dialog"

string_prop = bpy.props.StringProperty(name="String Prop")

def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)

def execute(self, context):
# Whatsoever needs to be done...
return {'FINISHED'}

self.layout.operator(MyDialog.bl_idname)

if __name__ == "__main__":

bpy.utils.register_class(MyDialog)

layout.operator_context = "INVOKE_DEFAULT"


You need to define an operator which uses calls invoke_props_dialog from its invoke function. Then reference this operator from your menu.

• An operator like pasteall.org/53035/python ? That works from Search, but doesn't from a menu. – PLyczkowski Jul 24 '14 at 12:04
• please include sample code in question, better then referencing external sites which may become dead links. – ideasman42 Jul 24 '14 at 12:52
• Done.---------- – PLyczkowski Jul 24 '14 at 14:12