【问题标题】:How to automatically handle DialogBoxShowing event in Python(Revit Dynamo)?如何在 Python(Revit Dynamo)中自动处理 DialogBoxShowing 事件?
【发布时间】:2017-12-09 17:50:43
【问题描述】:

如何在 Python (Dynamo) 中订阅 Revit 事件?

特别是 DialogBoxShowing,以便我可以查看它是否是“带有临时隐藏/隔离的导出”警告并选择“打开并导出临时隔离模式”?

这里是用 C# 完成的:

http://thebuildingcoder.typepad.com/blog/2013/03/export-wall-parts-individually-to-dxf.html

请参阅子标题:处理和消除警告消息

谢谢!

【问题讨论】:

    标签: revit-api revitpythonshell pyrevit


    【解决方案1】:

    为了让它比教程中的更简单:

    在 Revit 内部,使用 RevitPythonShell,事件订阅部分可以非常简单。

    事件处理程序只是一个带有两个参数的可调用对象:senderevent。然后事件,或者发送者给出参数来玩,DialogId and OverrideResultin our case.

    为了保留 Building Coder 示例,让我们继续:

    def on_dialog_open(sender, event):
        try:
            if event.DialogId == 'TaskDialog_Really_Print_Or_Export_Temp_View_Modes':
                event.OverrideResult(1002) 
                # 1001 call TaskDialogResult.CommandLink1
                # 1002 call TaskDialogResult.CommandLink2
                # int(TaskDialogResult.CommandLink2) to check the result
        except Exception as e:
            pass #print(e) # uncomment this to debug 
    

    您只需使用以下语法将此函数插入​​事件:

    __uiControlledApplication__.DialogBoxShowing += on_dialog_open

    这可以在 RevitPythonShell 的启动文件中完成:

    C:\Users\USERNAME\AppData\Roaming\RevitPythonShell2017\startup.py

    (或在插件的启动部分)

    如果不再需要处理程序,即在 Revit 关闭时(查看教程了解更多详细信息),更好的方法是取消注册处理程序:

    __uiControlledApplication__.DialogBoxShowing -= on_dialog_open


    如果您想在控制台中尝试此操作,可以使用:

    def on_dialog_open(sender, event):
        # [...]
    
    __revit__.DialogBoxShowing += on_dialog_open 
    

    在您尝试导出后:

    __revit__.DialogBoxShowing -= on_dialog_open


    编辑:结果命令的快捷方式(感谢 Callum!)

    ('Cancel', 2)
    ('Close', 8)
    ('CommandLink1', 1001)
    ('CommandLink2', 1002)
    ('CommandLink3', 1003)
    ('CommandLink4', 1004)
    ('No', 7)
    ('None', 0)
    ('Ok', 1)
    ('Retry', 4)
    ('Yes', 6)
    

    【讨论】:

    • 哇,这真的很有帮助,我马上试试。谢谢!
    • 还有一个问题,因为我刚接触 Python:如果我在 Dynamo 中使用 Python 节点,而不是构建插件,我会插入“uiControlledApplication.DialogBoxShowing += on_dialog_open" 代码到 Python 节点的启动行而不是插件的启动部分?
    • @JayW 我不太习惯 Dynamo,你可以问这个on the forum 来确定。您需要的是对Autodesk.Revit.UI.UIApplication Class 或Autodesk.Revit.UI.UIControlledApplication 的引用,最后一个只能在启动时访问
    【解决方案2】:

    (抱歉,没有足够的声誉将此作为评论添加到 PRMoureu 的回复中......)

    稍微扩展一下对话框的处理...

    订阅 DialogBoxShowing 非常强大,我们刚刚推出了一个对话框抑制器来消除令人沮丧的“你想把墙连接到你刚制作的地板上吗”和“你想把这些墙连接到屋顶上吗” '。它还可以用于查看用户经常遇到的错误等。

    • 调查 Dialogs 消息文本:event.Message
    • 向对话框回复“取消”:event.OverrideResult(0)
    • 向对话框回复“是”:event.OverrideResult(1)
    • 向对话框回复“OK”:event.OverrideResult(6)

    【讨论】:

    • 现在我想知道我是否给出了正确的数字,事实上我现在无法测试它,但也许我们应该使用int(TaskDialogResult.CommandLink1)
    • 你真的应该为这个+1,我搞砸了数字......现在更新
    【解决方案3】:

    回答你的第一个问题。尝试阅读 Pierre Moureu 的本教程:https://github.com/PMoureu/samples-Python-RPS/tree/master/Tutorial-IUpdater。 他订阅了一个 IUpdater。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-12
      • 1970-01-01
      相关资源
      最近更新 更多