Constructors and creating a new transaction

A reader asked for some more information about this line of code:

Transaction t = new Transaction(document,”Modify Mark values”);

What is happening here is that a new Transaction object is being created using the Transaction constructor. The transaction must be associated with a document (you can have several open documents co-existing simultaneously in your Revit API code).

You will also need to give your constructor a name. This can be done when the transaction is created as above, or you can use the constructor that requires only a document and specify the name later using the Transaction.SetName() method. The name of the transaction can be any string that you want. If the transaction is committed (which means that it successfully completed) then the end-user will see the name of the transaction in the Undo menu.

Creating a transaction does not automatically start the transaction. That must be done separately with the Start method. When you are finished with the changes to the model, use the Commit method. Or you can use the Rollback method if you don’t want to commit the changes that were made after starting the transaction.


2 thoughts on “Constructors and creating a new transaction

  1. Note that that a transaction’s name can also be set by supplying a name to the Start method. It should probably be also noted that starting a transaction closes the opportunity for (re-)naming it. Although an exception would not be thrown otherwise, it make sense to use the SetName method only before a transaction is started, being that either after it was just constructed, or after it was once committed (or rolled back).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s