打开 Revit 文件时处理失败(在任何事务之前)

Handling failures when opening a Revit file (before any transaction)

我正在用 C# 开发 Revit 插件,用于从 Revit 文件导出数据。该插件通过设计自动化 API 使用(即,显然没有用户界面)。对于某些 RVT 文件,整个过程工作正常。不幸的是,对于其他一些文件,文档打开失败 任何事务开始之前,所以我正在努力了解如何捕获这些打开错误(并可能删除相应的失败元素) ,类似于官方文档 inside transactions using IFailuresPreprocessor.

中的建议

有人对如何处理文档打开过程中的错误有什么建议吗?对不起,如果我错过了一些明显的东西。谢谢!

此处提供了部分 C# 代码(基本代码,如设计自动化教程中的代码)以及错误日志。

    if (data == null) throw new ArgumentNullException(nameof(data));

    Application rvtApp = data.RevitApp;
    if (rvtApp == null) throw new InvalidDataException(nameof(rvtApp));

    string modelPath = data.FilePath;
    if (String.IsNullOrWhiteSpace(modelPath)) throw new InvalidDataException(nameof(modelPath));

    Document doc = data.RevitDoc;
    if (doc == null) throw new InvalidOperationException("Could not open document.");

    using (Transaction transaction = new Transaction(doc))
    {
        ...
    }

来自 Design Automation 的日志报告 API:

[03/18/2022 10:18:46] Initialize and  get RCE: (VersionBuild) 22.1.21.13 (VersionNumber) 2022 (SubVersionNumber) 2022.1.2
[03/18/2022 10:31:11] Failure #0: FailureDefinitionId-'0d5f227d-a4fd-4bc2-b539-1a13cd9a9173', Severity-'Error', Description-'Line is too short.', Resolution-'Delete Element(s)'.
[03/18/2022 10:31:11] Failure: Unable to continue because of posted errors. Rolling back transaction.
[03/18/2022 10:31:17] Autodesk.Revit.Exceptions.OperationCanceledException: Opening was canceled.
[03/18/2022 10:31:17]    at Autodesk.Revit.ApplicationServices.Application.OpenDocumentFile(ModelPath modelPath, OpenOptions openOptions)
[03/18/2022 10:31:17]    at DesignAutomationFramework.DesignAutomationData..ctor(Application revitApp, String mainModelPath)
[03/18/2022 10:31:17]    at DesignAutomationFramework.DesignAutomationReadyEventArgs..ctor(Application revitApp, String mainModelPath)
[03/18/2022 10:31:17]    at DesignAutomationFramework.DesignAutomationBridge.SetDesignAutomationReady(Application revitApp, String mainModelPath)
[03/18/2022 10:31:17]    at RevitCoreEngineTest.RceConsoleApplication.Program.UserMain(CommandLineArgs cl)
[03/18/2022 10:31:19] RESULT: Failure - Result of running user app is failure
[03/18/2022 10:31:19] Finished running.  Process will return: TestError

warning swallower has been used successfully in Forge Design Automation for Revit. You can also check out the other suggestions by The Building Coder or Detecting and Handling Dialogues and Failures, as well as the topic group on DA4R – Design Automation for Revit. It includes a demonstration of adapting the warning swallower for DA4R.