Download Revit 2014 Platform API Developers Guidelines

Transcript
}
}
return FailureProcessingResult.Continue;
}
}
FailuresProcessing Event
The FailuresProcessing event is most suitable for applications that want to provide custom failure handling without a user interface, either for
the entire session or for many unrelated transactions. Some use cases for handling failures via this event are:
• automatic removal of certain warnings and/or automatic resolving of certain errors based on office standards (or other criteria)
• custom logging of failures
The FailuresProcessing event is raised after IFailuresPreprocessor (if any) has finished. It can have any number of handlers, and all of them
will be invoked. Since event handlers have no way to return a value, the SetProcessingResult() on the event argument should be used to
communicate status. Only Continue, ProceedWithRollback or ProceedWithCommit can be set.
The following example shows an event handler for the FailuresProcessing event.
Code Region 26-4: Handling the FailuresProcessing Event
private void CheckWarnings(object sender, FailuresProcessingEventArgs e)
{
FailuresAccessor fa = e.GetFailuresAccessor();
IList<FailureMessageAccessor> failList = new List<FailureMessageAccessor>();
failList = fa.GetFailureMessages(); // Inside event handler, get all warnings
foreach (FailureMessageAccessor failure in failList)
{
// check FailureDefinitionIds against ones that you want to dismiss, FailureDefinitionId failID =
failure.GetFailureDefinitionId();
// prevent Revit from showing Unenclosed room warnings
if (failID == BuiltInFailures.RoomFailures.RoomNotEnclosed)
{
fa.DeleteWarning(failure);
}
}
}
FailuresProcessor
The IFailuresProcessor interface gets control last, after the FailuresProcessing event is processed. There is only one active IFailuresProcessor
in a Revit session. To register a failures processor, derive a class from IFailuresProcessor and register it using the
Application.RegisterFailuresProcessor() method. If there is previously registered failures processor, it is discarded. If a Revit add-in opts to
register a failures processor for Revit that processor will become the default error handler for all Revit errors for the session and the standard
Revit error dialog will not appear. If no failures processors are set, there is a default one in the Revit UI that invokes all regular Revit error
dialogs. FailuresProcessor should only be overridden to replace the existing Revit failure UI with a custom failure resolution handler, which
can be interactive or have no user interface.
If the RegisterFailuresProcessor() method is passed NULL, any transaction that has any failures is silently aborted (unless failures are
resolved by first two steps of failures processing).
The IFailuresProcessor.ProcessFailures() method is allowed to return WaitForUserInput, which leaves the transaction pending. It is expected
that in this case, FailuresProcessor leaves some UI on the screen that will eventually commit or rollback a pending transaction - otherwise
the pending state will last indefinitely, essentially freezing the document.