Commits all changes made to the model during the transaction.
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 22.0.0.0 (22.1.0.0)
Syntax
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 a user actions.
Until committing is fully finalized, no changes to the document can be made
(including starting of new transactions).
The returned status does not have to be necessarily the same as
the status returned by GetStatus()()()() even when the method is called
immediately after committing the transaction. Such a difference may happen due to actions
made by a transaction finalizer, if there was one set.
(See FailureHandlingOptions for more details.)
Remarks
Examples
CopyC#
public bool CreateLevel(Autodesk.Revit.DB.Document document, double elevation)
{
using (Transaction transaction = new Transaction(document, "Creating Level"))
{
if( TransactionStatus.Started == transaction.Start())
{
if (null != Level.Create(document, elevation))
{
return (TransactionStatus.Committed == transaction.Commit());
}
transaction.RollBack();
}
}
return false;
}
CopyVB.NET
Public Function CreateLevel(document As Autodesk.Revit.DB.Document, elevation As Double) As Boolean
Using transaction As New Transaction(document, "Creating Level")
If TransactionStatus.Started = transaction.Start() Then
If Level.Create(document, elevation) IsNot Nothing Then
Return (TransactionStatus.Committed = transaction.Commit())
End If
transaction.RollBack()
End If
End Using
Return False
End Function
Exceptions
Exception | Condition |
---|
Autodesk.Revit.Exceptions..::..InvalidOperationException |
Document is a linked file. Transactions can only be used in primary documents (projects or families.)
-or-
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