1
$\begingroup$

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

The dialog invokes properly from Search, but not from a 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)
$\endgroup$
  • 2
    $\begingroup$ 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/… $\endgroup$ – CoDEmanX Sep 22 '14 at 18:50
1
$\begingroup$

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'}

def my_menu_addition(self, context):
    self.layout.operator(MyDialog.bl_idname)

if __name__ == "__main__":

    bpy.utils.register_class(MyDialog)
    bpy.types.INFO_MT_file.append(my_menu_addition)
$\endgroup$
0
$\begingroup$

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.