Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 16.0.0.0 (16.0.0.0)
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
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

public bool CreateLevel(Autodesk.Revit.DB.Document document, double elevation)
{
// 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, "Creating Level"))
{
// Must start a transaction to be able to modify a document
if( TransactionStatus.Started == transaction.Start())
{
if (null != Level.Create(document, elevation))
{
// For many various reasons, a transaction may not be committed
// if the changes made during the transaction do not result a valid model.
// If committing a transaction fails or is canceled by the end user,
// the resulting status would be RolledBack instead of Committed.
return (TransactionStatus.Committed == transaction.Commit());
}
// For we were unable to create the level, we will roll the transaction back
// (although on this simplified case we know there weren't any other changes)
transaction.RollBack();
}
}
return false;
}

Public Function CreateLevel(document As Autodesk.Revit.DB.Document, elevation As Double) As Boolean
' 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, "Creating Level")
' Must start a transaction to be able to modify a document
If TransactionStatus.Started = transaction.Start() Then
If Level.Create(document, elevation) IsNot Nothing Then
' For many various reasons, a transaction may not be committed
' if the changes made during the transaction do not result a valid model.
' If committing a transaction fails or is canceled by the end user,
' the resulting status would be RolledBack instead of Committed.
Return (TransactionStatus.Committed = transaction.Commit())
End If
' For we were unable to create the level, we will roll the transaction back
' (although on this simplified case we know there weren't any other changes)
transaction.RollBack()
End If
End Using
Return False
End Function
Exceptions
Exception | Condition |
---|---|
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. |