To create your own UI or fully automated tool to process Revit Failures, derive a class from this interface.
Namespace: Autodesk.Revit.DBAssembly: RevitAPI (in RevitAPI.dll) Version: 21.0.0.0 (21.1.1.109)
Syntax
C# |
---|
public interface IFailuresProcessor |
Visual Basic |
---|
Public Interface IFailuresProcessor |
Visual C++ |
---|
public interface class IFailuresProcessor |
Remarks
To override Revit default Failures Processing UI, instantiate your own processor derived from this interface
and register it in Revit application.
Examples

[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; } } }

<Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)> _ Public Class MyFailuresUI Implements IExternalApplication Shared m_appId As New AddInId(New Guid("9F179363-B349-4541-823F-A2DDB2B86AF3")) Public Function OnStartup(application As UIControlledApplication) As Autodesk.Revit.UI.Result Implements IExternalApplication.OnStartup Dim myFailUI As IFailuresProcessor = New FailUI() 'Autodesk.Revit.ApplicationServices.Application.RegisterFailuresProcessor(myFailUI); Return Result.Succeeded End Function Public Function OnShutdown(application As UIControlledApplication) As Autodesk.Revit.UI.Result Implements IExternalApplication.OnShutdown Return Result.Succeeded End Function Public Class FailUI Implements IFailuresProcessor Public Sub Dismiss(document As Document) Implements IFailuresProcessor.Dismiss ' 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 End Sub Public Function ProcessFailures(failuresAccessor As FailuresAccessor) As FailureProcessingResult Implements IFailuresProcessor.ProcessFailures Dim resolutionTypeList As IList(Of FailureResolutionType) = New List(Of FailureResolutionType)() Dim failList As IList(Of FailureMessageAccessor) = New List(Of FailureMessageAccessor)() ' Inside event handler, get all warnings failList = failuresAccessor.GetFailureMessages() Dim errorString As String = "" Dim hasFailures As Boolean = False For Each failure As FailureMessageAccessor In failList ' check how many resolutions types were attempted to try to prevent ' entering infinite loop resolutionTypeList = failuresAccessor.GetAttemptedResolutionTypes(failure) If resolutionTypeList.Count >= 3 Then TaskDialog.Show("Error", "Cannot resolve failures - transaction will be rolled back.") Return FailureProcessingResult.ProceedWithRollBack End If errorString += "IDs " For Each id As ElementId In failure.GetFailingElementIds() errorString += id.ToString() + ", " hasFailures = True Next errorString += vbLf & "Will be deleted because: " + failure.GetDescriptionText() + vbLf failuresAccessor.DeleteElements(TryCast(failure.GetFailingElementIds(), IList(Of ElementId))) Next If hasFailures Then TaskDialog.Show("Error", errorString) Return FailureProcessingResult.ProceedWithCommit End If Return FailureProcessingResult.[Continue] End Function End Class End Class