Suppressing Revit Warnings

In Revit there are different types of warnings. The most recurring ones are:

  1. Transaction related warnings
  2. Warnings displayed when the model is open

Jeremy Tammik suggests 3 methods:

  1. DialogBoxShowing event, which can be used to dismiss a dialogue programmatically.
  2. The Revit 2011 API also includes a comprehensive failure processing API, which can do much more than the DialogBoxShowing event.
  3. If all else fails and you just want to get rid of the dialogue box by any means, you can also use the Windows API to detect when it is displayed and dismiss it using my dialogue clicker application to suppress it.

The Warning Swallower deals with the transaction related warnings. Here’s the solution from the Revit Samples CmdPreprocessFailure.cs

For opening warnings, we can’t use the Warning Swallower. This post Open Document and ignore errors explains step by step how to dismiss a dialogue:

  1. If you want to run the macro in Revit zero state mode, import the Autodesk.Revit.ApplicationServices namespace and create a new UIApplication
    UIApplication uiapp = new UIApplication(Application);	
    Application app = uiapp.Application;
    
  2. Subscribe to the DialogBoxShowing event (the DialogBoxShowing event can be found in the Autodesk.Revit.UI.Events namespace).
    uiapp.DialogBoxShowing += new EventHandler<DialogBoxShowingEventArgs>(DialogBoxShowing);
    

Depending on the type of the dialog that is being shown, the event’s argument’s type varies as follows:

  • When it is a dialog box, the event’s argument is an object of DialogBoxShowingEventArgs .
  • When it is a message box, the event’s argument is an object of MessageBoxShowingEventArgs ,which is subclass of DialogBoxShowingEventArgs.
  • When it is a task dialog, the event’s argument is an object of TaskDialogShowingEventArgs ,which is subclass of DialogBoxShowingEventArgs.
  1. Create a void method to access the correct argument’s type. In this case a TaskDialog:
    void DialogBoxShowing(object sender, DialogBoxShowingEventArgs e) {
     TaskDialogShowingEventArgs e2 = e as TaskDialogShowingEventArgs;
    
  2. Loop through the TaskDialogShowingEventArgs DialogId to find the one to suppress. To suppress it use the OverrideResult() method:
    string s = string.Empty;			
     bool isConfirm = false;
     int dialogResult = 0;
    
     if (e2.DialogId.Equals("TaskDialog_Missing_Third_Party_Updaters"))
         {
         isConfirm = true;
         dialogResult = (int)TaskDialogResult.CommandLink1;
         }
        
     if (isConfirm)
         {
         e2.OverrideResult(dialogResult);
         s += ", auto-confirmed.";
         }
         else
         {
         s = string.Format(
         ", dialog id {0}, message '{1}'",
         e2.DialogId, e2.Message);
         forms.MessageBox.Show(s);				
         }			
    

You can find a snippet here

Written on November 24, 2018