首页 > 解决方案 > Blender Python:取消运算符而不关闭 props_dialog

问题描述

我正在开发一个 Blender Add-on,而 Blender Operators 的默认“Invoke -> Execute -> Close”流程对我来说并不是最友好的。我很确定我错过了一些东西。

我有一个layout_props_dialog

layout_props_dialog add_fixture

当用户单击“确定”时,我需要在允许操作员运行之前验证一些字段。但是,CANCELLED从该execute方法返回会关闭对话框,这是一种糟糕的 UX 模式。

我知道模态,但这似乎不是它的常见情况,因为在正确填写表格后,动作(添加固定装置)只发生一次。

# DMX_Fixture_AddEdit contains prop declarations and the draw method.

class DMX_OT_Fixture_Add(DMX_Fixture_AddEdit, Operator):
    bl_label = "DMX: Add Fixture"
    bl_idname = "dmx.add_fixture"
    bl_options = {'REGISTER','UNDO'}

    def execute(self, context):
        scene = context.scene
        dmx = scene.dmx
        if (self.name in bpy.data.collections):
            return {'CANCELLED'}
        if (not len(self.profile)):
            self.report({'ERROR'}, "No GDTF Profile selected.")
            return {'CANCELLED'}
        if (not len(self.mode)):
            self.report({'ERROR'}, "No DMX Mode selected.")
            return {'CANCELLED'}
        for i in range(self.units):
            dmx.addFixture(self.name+" "+str(i+1), self.profile, self.universe, self.address, self.mode, list(self.gel_color))
        return {'FINISHED'}

    def invoke(self, context, event):
        self.name = "Fixture "+str(len(context.scene.dmx.fixtures)+1)
        self.units = 1
        DMX_Fixture_AddEdit.profile_list_items = []
        wm = context.window_manager
        return wm.invoke_props_dialog(self)

所以,简而言之,我需要取消执行方法而不关闭layout_prop_dialog. 我也尝试过RUNNING_MODAL,PASS_THROUGHINTERFACE. 所有人都表现出相同的行为。

有任何想法吗?

标签: pythonblender

解决方案


推荐阅读