IFailuresProcessor Interface

To create your own UI or fully automated tool to process Revit Failures, derive a class from this interface.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public interface IFailuresProcessor

The IFailuresProcessor type exposes the following members.

Methods
 NameDescription
Public methodDismiss 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 methodProcessFailures Method that Revit will invoke to process failures at the end of transaction.
Top
Remarks
To override Revit default Failures Processing UI, instantiate your own processor derived from this interface and register it in Revit application.
Example
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]

public class MyFailuresUI : IExternalApplication
{
    static AddInId m_appId = new AddInId(new Guid("9F179363-B349-4541-823F-A2DDB2B86AF3"));
    public Result OnStartup(UIControlledApplication application)
    {
        IFailuresProcessor myFailUI = new FailUI();
        Autodesk.Revit.ApplicationServices.Application.RegisterFailuresProcessor(myFailUI);
        return Result.Succeeded;
    }

    public Result OnShutdown(UIControlledApplication application)
    {
        return Result.Succeeded;
    }

    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)
        {
            IList<FailureResolutionType> resolutionTypeList = new List<FailureResolutionType>();
            IList<FailureMessageAccessor> failList = new List<FailureMessageAccessor>();
            // Inside event handler, get all warnings
            failList = failuresAccessor.GetFailureMessages(); 
            string errorString = "";
            bool hasFailures = false;
            foreach (FailureMessageAccessor failure in failList)
            {
                // check how many resolutions types were attempted to try to prevent
                // entering infinite loop
                resolutionTypeList = failuresAccessor.GetAttemptedResolutionTypes(failure);
                if (resolutionTypeList.Count >= 3)
                {
                    TaskDialog.Show("Error", "Cannot resolve failures - transaction will be rolled back.");
                    return FailureProcessingResult.ProceedWithRollBack;
                }

                errorString += "IDs ";
                foreach (ElementId id in failure.GetFailingElementIds())
                {
                    errorString += id.ToString() + ", ";
                    hasFailures = true;
                }
                errorString += "\nWill be deleted because: " + failure.GetDescriptionText() + "\n";
                failuresAccessor.DeleteElements(failure.GetFailingElementIds() as IList<ElementId>);
            }
            if (hasFailures)
            {
                TaskDialog.Show("Error", errorString);
                return FailureProcessingResult.ProceedWithCommit;
            }

            return FailureProcessingResult.Continue;
        }
    }
}
See Also