Transaction Class


Transaction Class

Transactions are context-like objects that guard any changes made to a Revit model
Inheritance Hierarchy
System Object
Autodesk.Revit.DB Transaction

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.3.0.0 (25.3.0.0)
Syntax
public class Transaction : IDisposable

The Transaction type exposes the following members.

Constructors
Name Description
Public method Transaction(Document) Instantiates a transaction object.
Public method Transaction(Document, String) Instantiates a transaction object
Top
Properties
Name Description
Public property IsValidObject Specifies whether the .NET object represents a valid Revit entity.
Top
Methods
Name Description
Public method Commit Commits all changes made to the model during the transaction.
Public method Commit(FailureHandlingOptions) Commits all changes made to the model during the transaction.
Public method Dispose Releases all resources used by the Transaction
Public method Equals Determines whether the specified object is equal to the current object.
(Inherited from Object )
Public method GetFailureHandlingOptions Returns the current failure handling options.
Public method GetHashCode Serves as the default hash function.
(Inherited from Object )
Public method GetName Returns the transaction's name.
Public method GetStatus Returns the current status of the transaction.
Public method GetType Gets the Type of the current instance.
(Inherited from Object )
Public method HasEnded Determines whether the transaction has ended already.
Public method HasStarted Determines whether the transaction has been started yet.
Public method RollBack Rolls back all changes made to the model during the transaction.
Public method RollBack(FailureHandlingOptions) Rolls back all changes made to the model during the transaction.
Public method SetFailureHandlingOptions Sets options for handling failures to be used when the transaction is being committed or rolled back.
Public method SetName Sets the transaction's name.
Public method Start Starts the transaction.
Public method Start(String) Starts the transaction with an assigned name.
Public method ToString Returns a string that represents the current object.
(Inherited from Object )
Top
Remarks

Any change to a document can only be made while there is an active transaction open for that document. Changes do not become part of the document until the active transaction is committed . Consequently, all changes made in a transaction can be rolled back either explicitly or implicitly by the transaction's destructor.

A document can have only one transaction open at any given time.

Transactions cannot be started when the document is in read-only mode, either permanently or temporarily. See the Document class methods IsReadOnly and IsModifiable for more details.

Transactions in linked documents are not permitted, for linked documents are not allowed to be modified.

If a transaction was started and not finished yet by the time the Transaction object is about to be disposed, the default destructor will roll it back automatically, thus all changes made to the document while this transaction was open will be discarded. It is not recommended to rely on this default behavior though. Instead, it is advised to always call either Commit or RollBack explicitly before the transaction object gets disposed. Please note that unless invoked explicitly the actual destruction of an object in managed code might not happen until the object is collected by the garbage collector.

See Also