1

I'm developing a Revit plugin in C# for exporting data from Revit files. This plugin is used through the Design Automation API (i.e. without user interface, obviously). The whole process works fine for some RVT files. Unfortunately, for some other files, the document opening fails before any transaction has started, so I'm struggling to see how I can catch these opening errors (and possibly delete the corresponding failed elements), similarly to what is suggested in the official documentation inside transactions using IFailuresPreprocessor.

Does anyone have suggestion on how to handle errors during the document opening itself? Sorry if I miss something obvious. Thanks!

Part of the C# code is available here (basic code, like in the Design Automation tutorials), as well as the error logs.

    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))
    {
        ...
    }

Log report from 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
  • 1
    Have you already gone through this documentation and tried it? https://forge.autodesk.com/en/docs/design-automation/v3/developers_guide/revit_specific/handling-failures/ Did it not work? – Rahul Bhobe Mar 18 '22 at 12:46
  • 1
    Hello @RahulBhobe. Thanks a lot for your reference. Now I managed to make it work by developing my own failure processor (based on the existing sample code) and using "Application.RegisterFailuresProcessor(myFailureProcessor)", as suggested in the doc. –  Mar 22 '22 at 17:19

1 Answers1

1

The 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.

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • Hello Jeremy. Sorry for my late reply and thanks for your answer! By reading the doc more carefully (incl. @RahulBhobe's reference), I managed to make it work using the "Application.RegisterFailuresProcessor(myFailureProcessor)" paradigm. –  Mar 22 '22 at 17:17
  • Awesome great!! – Rahul Bhobe Mar 22 '22 at 18:30