Capture Warning message during the save with a Revit Batch Startup approach

Capture Warning message during the save with a Revit Batch Startup approach

pmeigneux
Advocate Advocate
1,142 Views
8 Replies
Message 1 of 9

Capture Warning message during the save with a Revit Batch Startup approach

pmeigneux
Advocate
Advocate

Hello,

 

I would like to capture the warning messages during the save when I am launching Revit in background (Batch).

 

I am currently not able to activate the FailUI class to capture the warning message during the save with this Revit startup approach. Is there a public API which allow this operation?

 

I provide you a sample of code to illustrate my words.

 

namespace TEST1

{

       /// <summary>

       /// This application's main class. The class must be Public.

       /// </summary>

       public class ProjectAddPanel : IExternalApplication

       {

             public Result OnStartup(UIControlledApplication application)

             {

                    application.ControlledApplication.ApplicationInitialized += new EventHandler<Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs>(TestBatch);

                     Autodesk.Revit.DB.IFailuresProcessor MyFailUI = new FailUI();

                     Autodesk.Revit.ApplicationServices.Application.RegisterFailuresProcessor(MyFailUI);

                     return Result.Succeeded;

             }

 

             public Result OnShutdown(UIControlledApplication application)

             {

                                                application.ControlledApplication.ApplicationInitialized -= new EventHandler<Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs>(TestBatch);

                     return Result.Succeeded;

             }

 

             public void TestBatch (object sender, Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs e)

             {

                    // Sender is an Application instance:

                    Autodesk.Revit.ApplicationServices.Application app = sender as Autodesk.Revit.ApplicationServices.Application;

 

                    // However, UIApplication can be instantiated from Application.

                    UIApplication uiapp = new UIApplication(app);

 

                    // Open File

                    uiapp.OpenAndActivateDocument(« test.rvt »);

                    UIDocument uidoc = uiapp.ActiveUIDocument;

                    Doc = uidoc.Document;

 

                    Doc.Save();

             }

 

                   

             }

             public class FailUI : IFailuresProcessor

             {

                     public void Dismiss(Document document)

                     {

                           // This method is being called in case of exception or document destruction to

                           // dismiss any possible pending failure UI that may have left on the screen

                     }

 

                     public FailureProcessingResult ProcessFailures(FailuresAccessor failuresAccessor)

                     {

                           failuresAccessor.DeleteAllWarnings();

                           return FailureProcessingResult.Continue;

                     }

             }

       }

}

 

 

 

0 Likes
1,143 Views
8 Replies
Replies (8)
Message 2 of 9

jeremytammik
Autodesk
Autodesk

Dear Philippe,

 

Does the new interface to retrieve all warnings help?

 

http://thebuildingcoder.typepad.com/blog/2017/04/whats-new-in-the-revit-2018-api.html#3.18

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 9

pmeigneux
Advocate
Advocate

Hi Jeremy,

 

My code uses Revit 2016, Revit 2017 and Revit 2018.

 

For Revit 2018, how to use for my GetWarnings batch program to never display warnings?

 

And for Revit 2016 and Revit 2017, my code works very well in interactive mode and not in batch mode.

 

Do you have a solution?

 

Philippe.

0 Likes
Message 4 of 9

Revitalizer
Advisor
Advisor

Hi Philippe,

 

I think it would have been better to say "intercept" or "suppress" instead of "capture".

But the mention of "batch"  should have clarified that, anyway.

 

I would suggest to look at the ErrorHandling sample in the Revit SDK, at the Command.cs file.

 

There is a FailuresProcessing event with the Application class (and also with the ControlledApplication class).

 

That means, independent of your own Transactions, you can intercept the FailuresProcessing in a general context.

I suppose you also can intercept those warnings when saving.

But that's an assumption, I did't try this.

 

Don't forget to unsubscribe from the event since it prevents the user from being warned at all, after the batch process.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 5 of 9

pmeigneux
Advocate
Advocate

Hi,

 

My save file stops because of a warning that is directed to the screen. Only wants to capture these warnings and delete them to complete the file save.

 

Philippe.

0 Likes
Message 6 of 9

Revitalizer
Advisor
Advisor

Hi,

 

I've already got it: you want to suppress those warnings, preventing them from popping up.

Did you try the approach I suggested, does it work or not?

 

The sample file I mentioned shows how to set the FailureProcessingResult respectively to resolve a failure.

 

private void FailuresProcessing(object sender, Autodesk.Revit.DB.Events.FailuresProcessingEventArgs e)
{
    FailuresAccessor failuresAccessor = e.GetFailuresAccessor();
    //failuresAccessor
    String transactionName = failuresAccessor.GetTransactionName();

    IList<FailureMessageAccessor> fmas = failuresAccessor.GetFailureMessages();
    if (fmas.Count == 0)
    {
        e.SetProcessingResult(FailureProcessingResult.Continue);
        return;
    }

    if (transactionName.Equals("Error_FailuresProcessingEvent"))
    {
        foreach (FailureMessageAccessor fma in fmas)
        {
           FailureDefinitionId id = fma.GetFailureDefinitionId();
           if (id == Command.m_idError)
           {
                failuresAccessor.ResolveFailure(fma);
           }
        }

        e.SetProcessingResult(FailureProcessingResult.ProceedWithCommit);
        return;
    }

    e.SetProcessingResult(FailureProcessingResult.Continue);
}

 

In this context, you can call the failuresAccessor.DeleteWarning(fma) method, and that's what you want to perform, don't you?

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 7 of 9

DavidWoodCT
Enthusiast
Enthusiast

Hi Phillippe,

 

What is the warning that stops your background save?

 

We have found, when batch processing, that some 'problems' don't get processed by the Warnings / Failures API. They just get posted straight to screen as a dialog, so they have to be caught and suppressed using DialogBoxShowing.

 

HTH

 

David

 

 

Message 8 of 9

pmeigneux
Advocate
Advocate

Hi,

 

Doesn't work for this warning :

0 Likes
Message 9 of 9

TimonHazell-WPM
Contributor
Contributor

Was a solution found for this, I'm dealing with the same issue right now.

0 Likes