Skip to main content
verified that the 2.8x version works on 2.93.5, so edited to indicate so.
Source Link
Marty Fouts
  • 34k
  • 10
  • 40
  • 87

Blender 2.8x and beyond

Blender 2.8x and beyond

Blender 2.8x and beyond

Blender 2.8x

Blender 2.8x

Blender 2.8x

Blender 2.8x and beyond

Blender 2.8x and beyond

Blender 2.8x and beyond

invoke_popup for completeness
Source Link
brockmann
  • 13k
  • 4
  • 52
  • 94

Simple Popup

For the sake of completeness, you can also display a popup without any OK button by using wm.invoke_popup(self):

import bpy class SimplePopUpOperator(bpy.types.Operator): """Really?""" bl_idname = "my_category.custom_popup_dialog" bl_label = "Do you really want to do that?" bl_options = {'REGISTER', 'INTERNAL'} prop1: bpy.props.BoolProperty() prop2: bpy.props.BoolProperty() @classmethod def poll(cls, context): return True def execute(self, context): self.report({'INFO'}, "YES!") return {'FINISHED'} def invoke(self, context, event): return context.window_manager.invoke_popup(self) def draw(self, context): row = self.layout row.label(text="Do you really want to do that?") row.prop(self, "prop1", text="Property A") row.prop(self, "prop2", text="Property B") class OBJECT_PT_CustomPanel(bpy.types.Panel): bl_label = "My Panel" bl_idname = "OBJECT_PT_custom_panel" bl_space_type = "VIEW_3D" bl_region_type = "UI" bl_category = "Tools" bl_context = "objectmode" def draw(self, context): layout = self.layout layout.operator(SimplePopUpOperator.bl_idname) def register(): bpy.utils.register_class(OBJECT_PT_CustomPanel) bpy.utils.register_class(SimplePopUpOperator) def unregister(): bpy.utils.unregister_class(SimplePropConfirmOperator) bpy.utils.unregister_class(SimplePopUpOperator) if __name__ == "__main__": register() 

Simple Popup

For the sake of completeness, you can also display a popup without any OK button by using wm.invoke_popup(self):

import bpy class SimplePopUpOperator(bpy.types.Operator): """Really?""" bl_idname = "my_category.custom_popup_dialog" bl_label = "Do you really want to do that?" bl_options = {'REGISTER', 'INTERNAL'} prop1: bpy.props.BoolProperty() prop2: bpy.props.BoolProperty() @classmethod def poll(cls, context): return True def execute(self, context): self.report({'INFO'}, "YES!") return {'FINISHED'} def invoke(self, context, event): return context.window_manager.invoke_popup(self) def draw(self, context): row = self.layout row.label(text="Do you really want to do that?") row.prop(self, "prop1", text="Property A") row.prop(self, "prop2", text="Property B") class OBJECT_PT_CustomPanel(bpy.types.Panel): bl_label = "My Panel" bl_idname = "OBJECT_PT_custom_panel" bl_space_type = "VIEW_3D" bl_region_type = "UI" bl_category = "Tools" bl_context = "objectmode" def draw(self, context): layout = self.layout layout.operator(SimplePopUpOperator.bl_idname) def register(): bpy.utils.register_class(OBJECT_PT_CustomPanel) bpy.utils.register_class(SimplePopUpOperator) def unregister(): bpy.utils.unregister_class(SimplePropConfirmOperator) bpy.utils.unregister_class(SimplePopUpOperator) if __name__ == "__main__": register() 
Api links
Source Link
p2or
  • 16.3k
  • 10
  • 88
  • 146

When calling an operator via bpy.ops.* without any execution contextexecution context the execute() method of the respective operator runs by default. If the operator provides any kind of 'user interaction' like a 'confirmation dialog' in this case, then you can pass 'INVOKE_DEFAULT' as execution contextexecution context when calling the operator which will also run its invoke() method:

In order to display the operator as a button and also 'enable' its user interaction, you have to set the operator_contextoperator_context in the 'layout' before calling the operator:

For a custom conformation dialog you can wrap the operator into another one and invoke invoke_confirm(operator, event)invoke_confirm(operator, event) classmethod of the window-manager to confirm the execution by the user.

In order to display a popup, some properties and an OK 'button' you can return wm.invoke_props_dialog(self)wm.invoke_props_dialog(self) instead:

Note: bl_optionsbl_options of both examples are set to 'INTERNAL' which excludes the operators from search results, remove it if you'd like to run the operator via space bar/F3.

When calling an operator via bpy.ops.* without any execution context the execute() method of the respective operator runs by default. If the operator provides any kind of 'user interaction' like a 'confirmation dialog' in this case, then you can pass 'INVOKE_DEFAULT' as execution context when calling the operator which will also run its invoke() method:

In order to display the operator as a button and also 'enable' its user interaction, you have to set the operator_context in the 'layout' before calling the operator:

For a custom conformation dialog you can wrap the operator into another one and invoke invoke_confirm(operator, event) classmethod of the window-manager to confirm the execution by the user.

In order to display a popup, some properties and an OK 'button' you can return wm.invoke_props_dialog(self) instead:

Note: bl_options of both examples are set to 'INTERNAL' which excludes the operators from search results, remove it if you'd like to run the operator via space bar/F3.

When calling an operator via bpy.ops.* without any execution context the execute() method of the respective operator runs by default. If the operator provides any kind of 'user interaction' like a 'confirmation dialog' in this case, then you can pass 'INVOKE_DEFAULT' as execution context when calling the operator which will also run its invoke() method:

In order to display the operator as a button and also 'enable' its user interaction, you have to set the operator_context in the 'layout' before calling the operator:

For a custom conformation dialog you can wrap the operator into another one and invoke invoke_confirm(operator, event) classmethod of the window-manager to confirm the execution by the user.

In order to display a popup, some properties and an OK 'button' you can return wm.invoke_props_dialog(self) instead:

Note: bl_options of both examples are set to 'INTERNAL' which excludes the operators from search results, remove it if you'd like to run the operator via space bar/F3.

Blender 2.8x
Source Link
p2or
  • 16.3k
  • 10
  • 88
  • 146
Loading
more information added
Source Link
p2or
  • 16.3k
  • 10
  • 88
  • 146
Loading
more information added
Source Link
p2or
  • 16.3k
  • 10
  • 88
  • 146
Loading
more information added
Source Link
p2or
  • 16.3k
  • 10
  • 88
  • 146
Loading
Source Link
p2or
  • 16.3k
  • 10
  • 88
  • 146
Loading