TransactionRollBack Method |
Rolls back all changes made to the model during the transaction.
Namespace: Autodesk.Revit.DBAssembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntaxpublic TransactionStatus RollBack()
Public Function RollBack As TransactionStatus
public:
TransactionStatus RollBack()
member RollBack : unit -> TransactionStatus
Return Value
TransactionStatus
If finished successfully, this method returns TransactionStatus.RolledBack.
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 rolling back the transaction. Such difference may happen due to actions
made by a transaction finalizer, if there was one set.
(See FailureHandlingOptions for more details.)
ExceptionsException | Condition |
---|
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.
|
Remarks
By rolling back a transaction, all changes made to the model are discarded.
RollBack may only be called for a transaction that has been started.
(Use the
GetStatus method to check the current state.)
Be aware that rolling back may be delayed (as a result of failure handling.)
Callers should always check the returned status to test whether a transaction
was rolled back successfully. Only after rolling back is fully completed,
the transaction may be started again.
Examplepublic bool CreateGrid(Autodesk.Revit.DB.Document document, XYZ p1, XYZ p2)
{
using (Transaction transaction = new Transaction(document, "Creating Grid"))
{
if (TransactionStatus.Started == transaction.Start())
{
Line gridLine = Line.CreateBound(p1, p2);
if ((null != gridLine) && (null != Grid.Create(document, gridLine)))
{
if (TransactionStatus.Committed == transaction.Commit())
{
return true;
}
}
transaction.RollBack();
}
}
return false;
}
Public Function CreateGrid(document As Autodesk.Revit.DB.Document, p1 As XYZ, p2 As XYZ) As Boolean
Using transaction As New Transaction(document, "Creating Grid")
If TransactionStatus.Started = transaction.Start() Then
Dim gridLine As Line = Line.CreateBound(p1, p2)
If (gridLine IsNot Nothing) AndAlso (Grid.Create(document, gridLine) IsNot Nothing) Then
If TransactionStatus.Committed = transaction.Commit() Then
Return True
End If
End If
transaction.RollBack()
End If
End Using
Return False
End Function
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
See Also