0

我在搅拌机 2.80 中创建了一个对话框,以便能够插入一些值并通过“确定”按钮发送它们。

在“执行”函数内部执行了一些操作,最后关闭了窗口。但是,如果出现异常,则必须通过通知用户并保持对话框打开来处理问题。为此,我使用了 try-catch 块,但它不起作用:如果出现异常,无论返回值如何,对话框都会关闭。

有没有什么办法解决这一问题?

@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 
4

0 回答 0