Commits the transaction group.
Namespace:
Autodesk.Revit.DB
Assembly:
RevitAPI
(in RevitAPI.dll) Version: 2015.0.0.0 (2015.0.0.0)
Since:
2011
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
Return Value
If finished successfully, this method returns TransactionStatus.Committed.Remarks
Committing a group does not change the model. It only confirms the commitment of all inner groups and transactions.
Commit can be called only when all inner transaction groups and transactions are finished, i.e. after they were either committed or rolled back. If there is still a transaction or an inner transaction group open, an attempt to commit this outer group will cause an exception.
Examples
Copy
C#
public void GroupedOperations(Autodesk.Revit.DB.Document document)
{
// All and any transaction group should be enclosed in a 'using' block or guarded within
// a try-catch-finally blocks to guarantee that the group does not out-live its scope.
using (TransactionGroup transGroup = new TransactionGroup(document, "Level and Grid"))
{
if (transGroup.Start() == TransactionStatus.Started)
{
// We are going to call two methods, each having its own local transaction.
// For our compound operation to be considered successful, both the individual
// transactions must succeed. If either one fails, we will roll our group back,
// regardless of what transactions might have already been committed.
if (CreateLevel(document, 35.0) && CreateGrid(document, new XYZ(0, 0, 0), new XYZ(0, 10, 0)))
{
// The process of committing of a group does not do anything to the already committed
// transactions. They will stay available on the undo menu and may still be undone
// individually. If it is not desirable if one transaction from a multi-transaction
// operation can be undone by th end user, then the transaction group must be
// assimilated instead of committed. See TransactionGroup.Assimilate for details.
transGroup.Commit();
}
else
{
// Since we could not successfully finish at least one of the individual
// operation, we are going to roll the entire group back, which will
// undo any transaction already committed while this group was open.
transGroup.RollBack();
}
}
}
}
Copy
VB.NET
Public Sub GroupedOperations(document As Autodesk.Revit.DB.Document)
' All and any transaction group should be enclosed in a 'using' block or guarded within
' a try-catch-finally blocks to guarantee that the group does not out-live its scope.
Using transGroup As New TransactionGroup(document, "Level and Grid")
If transGroup.Start() = TransactionStatus.Started Then
' We are going to call two methods, each having its own local transaction.
' For our compound operation to be considered successful, both the individual
' transactions must succeed. If either one fails, we will roll our group back,
' regardless of what transactions might have already been committed.
If CreateLevel(document, 35.0) AndAlso CreateGrid(document, New XYZ(0, 0, 0), New XYZ(0, 10, 0)) Then
' The process of committing of a group does not do anything to the already committed
' transactions. They will stay available on the undo menu and may still be undone
' individually. If it is not desirable if one transaction from a multi-transaction
' operation can be undone by th end user, then the transaction group must be
' assimilated instead of committed. See TransactionGroup.Assimilate for details.
transGroup.Commit()
Else
' Since we could not successfully finish at least one of the individual
' operation, we are going to roll the entire group back, which will
' undo any transaction already committed while this group was open.
transGroup.RollBack()
End If
End If
End Using
End Sub
Exceptions
Exception | Condition |
---|---|
Autodesk.Revit.Exceptions InvalidOperationException | The Transaction group has not been started (its status is not 'Started').. -or- The transaction's document is currently in failure mode. Transaction groups cannot be closed until failure handling is finished. You may use a transaction finalizer to close a group after the failure handling ends. |