Blender 2.80: handle exceptions in the dialog

210 Views Asked by At

I created a dialog in blender 2.80 to be able to insert some values and send them through the "Ok" button.

Inside the "execute" function some operations are performed and, at the end, the window is closed. However, in case of exceptions, the problem must be handled by notifying the user and leaving the dialog box open. To do this I use a try-catch block but it does not work: in case of exception the dialog box closes whatever the returned value.

Is there any way to fix this?

@subscribe
class Test(Operator):

    bl_idname = "bl_idname"
    bl_label = "bl_label"
    bl_description = "bl_description"

    input_a = bpy.props.StringProperty(
        name = "name_a",
        default = "default"
    )

    input_b  = bpy.props.StringProperty(
        name = "name_b",
        default = "default"
    )

    input_c  = bpy.props.StringProperty(
        name = "name_c",
        default = "default"
    )

    def invoke(self, context, event):
        return context.window_manager.invoke_props_dialog(self, width = 450)
    
    def draw(self, context):
        col = self.layout.column(align = True)
        col.prop(self, "input_a")

        col = self.layout.column(align = True)
        col.prop(self, "input_b")

        col = self.layout.column(align = True)
        col.prop(self, "input_c")

    def execute(self, context):
        try:
            #something...
            return {"FINISHED"}
        
        except Exception as e:
            print(str(e))
            return {"CANCELLED"} #I also tried RUNNING_MODAL or PASS_THROUGH 
0

There are 0 best solutions below