SetFailureHandlingOptions Method


Sets options for handling failures to be used when the transaction is being committed or rolled back.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 2015.0.0.0 (2015.0.0.0)

Syntax

C#
public void SetFailureHandlingOptions(
	FailureHandlingOptions options
)
Visual Basic
Public Sub SetFailureHandlingOptions ( _
	options As FailureHandlingOptions _
)
Visual C++
public:
void SetFailureHandlingOptions(
	FailureHandlingOptions^ options
)

Parameters

options
Type: Autodesk.Revit.DB FailureHandlingOptions
An instance of FailureHandlingOptions to be applied to the transaction

Remarks

Options can be set at any time before the transaction is either committed or rolled back. See FailureHandlingOptions for details about available options. Once committed or rolled back, the transaction object will reset its options to their default values.

Examples

Copy C#
// All and any transaction should be enclosed in a 'using'
// block or guarded within a try-catch-finally blocks
// to guarantee that a transaction does not out-live its scope.
using (Transaction transaction = new Transaction(doc))
{
   // Before we modify a document, we must start a transaction
   transaction.Start("Creating room");

   // obtain the current options and add failures preprocessor to it.
   // Note: preprocessor implements IFailuresProcessor and will receive 
   // a notification about failures eventually posted during the transaction.
   FailureHandlingOptions options = transaction.GetFailureHandlingOptions();
   options.SetFailuresPreprocessor(new RoomWarningSwallower());
   transaction.SetFailureHandlingOptions(options);

   // Modify the document and commit the transaction.
   if (null != doc.Create.NewRoom(level, UV.Zero))
   {
      // Now, before the the transaction is committed, if there happened to 
      // be any failure, the preprocessor would receive them first and would
      // have the option to analyze them, and ignore or re-qualify them.
      transaction.Commit();
   }
   else  // could not create the room; no need to commit the transaction
   {
      transaction.RollBack();
   }
}
Copy VB.NET
Public Function Execute(commandData As ExternalCommandData, ByRef message As String, elements As ElementSet) As Autodesk.Revit.UI.Result Implements IExternalCommand.Execute
    Dim app As Autodesk.Revit.ApplicationServices.Application = commandData.Application.Application
    Dim doc As Document = commandData.Application.ActiveUIDocument.Document
    Dim uidoc As UIDocument = commandData.Application.ActiveUIDocument

    Dim collector As New FilteredElementCollector(doc)
    Dim elementCollection As ICollection(Of Element) = collector.OfClass(GetType(Level)).ToElements()
    Dim level As Level = elementCollection.Cast(Of Level)().ElementAt(0)


    ' All and any transaction should be enclosed in a 'using'
    ' block or guarded within a try-catch-finally blocks
    ' to guarantee that a transaction does not out-live its scope.
    Using transaction As New Transaction(doc)
        ' Before we modify a document, we must start a transaction
        transaction.Start("Creating room")

        ' obtain the current options and add failures preprocessor to it.
        ' Note: preprocessor implements IFailuresProcessor and will receive 
        ' a notification about failures eventually posted during the transaction.
        Dim options As FailureHandlingOptions = transaction.GetFailureHandlingOptions()
        options.SetFailuresPreprocessor(New RoomWarningSwallower())
        transaction.SetFailureHandlingOptions(options)

        ' Modify the document and commit the transaction.
        If doc.Create.NewRoom(level, UV.Zero) IsNot Nothing Then
            ' Now, before the the transaction is committed, if there happened to 
            ' be any failure, the preprocessor would receive them first and would
            ' have the option to analyze them, and ignore or re-qualify them.
            transaction.Commit()
        Else
            ' could not create the room; no need to commit the transaction
            transaction.RollBack()
        End If
    End Using


    Return Autodesk.Revit.UI.Result.Succeeded
End Function

Exceptions

Exception Condition
Autodesk.Revit.Exceptions ArgumentNullException A non-optional argument was NULL

See Also