Commit Method (FailureHandlingOptions)


Commits all changes made to the model during the transaction.

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

Syntax

C#
public TransactionStatus Commit(
	FailureHandlingOptions options
)
Visual Basic
Public Function Commit ( _
	options As FailureHandlingOptions _
) As TransactionStatus
Visual C++
public:
TransactionStatus Commit(
	FailureHandlingOptions^ options
)

Parameters

options
Type: Autodesk.Revit.DB FailureHandlingOptions
A set of options to be used for handling eventual failures during this call.

The options are only used temporarily during the commitment process. After the transaction is finished, the options will be reset to their default values.

Return Value

If finished successfully, this method returns TransactionStatus.Committed

Note it is possible the RolledBack status is returned instead as an outcome of failure handling. If TransactionStatus.Pending is returned it means that failure handling has not been finalized yet and Revit awaits user's actions. Until committing is fully finalized, no changes to the document can be made (including starting of new transactions).

Be aware that the returned status does not have to be necessarily the same like the status returned by GetStatus even when the method is called immediately after committing the transaction. Such difference may happen due to actions made by a transaction finalizer, if there was one set. (See FailureHandlingOptions for more details.)

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(document))
{
   // Must start the transaction first to be able to modify a document
   transaction.Start("Creating Level");

   if (null != Level.Create(document, elevation))
   {
      // If we have a few transactions chained (for whatever reason)
      // we may wish to collect eventual warnings, if any, and show
      // them only when the last transaction of the chain is committed.
      FailureHandlingOptions options = transaction.GetFailureHandlingOptions();

      // Now, showing of any eventual mini-warnings will be
      // postponed until the following transaction.
      transaction.Commit(options.SetDelayedMiniWarnings(true));

      // Note, after a transaction is committed, the used failure options
      // are lost and replaced with default options again.
   }
}
Copy VB.NET
' 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(document)
    ' Must start the transaction first to be able to modify a document
    transaction.Start("Creating Level")

If Level.Create(document, elevation) IsNot Nothing Then
   ' If we have a few transactions chained (for whatever reason)
   ' we may wish to collect eventual warnings, if any, and show
   ' them only when the last transaction of the chain is committed.
   Dim options As FailureHandlingOptions = transaction.GetFailureHandlingOptions()

   ' Now, showing of any eventual mini-warnings will be
   ' postponed until the following transaction.


   ' Note, after a transaction is committed, the used failure options
   ' are lost and replaced with default options again.
   transaction.Commit(options.SetDelayedMiniWarnings(True))
End If
End Using

Exceptions

Exception Condition
Autodesk.Revit.Exceptions ArgumentNullException A non-optional argument was NULL
Autodesk.Revit.Exceptions InvalidOperationException The current status of the transaction is not 'Started'. Transaction must be started before calling Commit or Rollback. -or- The transaction's document is currently in failure mode. No transaction operations are permitted until failure handling is finished.

See Also