Transactions, Sub-Transactions and Transaction Groups

Here is a recent query from a developer that led to a nice succinct overview of transactions, sub-transactions and transaction groups by Arnošt Löbel.

This makes a change from the recent rash of monster posts. The last ten posts were all rather overwhelming in size, and hopefully impressive in content as well. From Aril 16 until 29, I posted a total of 26228 words, 245504 bytes.

So let's keep this one short, sweet and to the point.

Question: When should I use a transaction group with transactions versus transaction with sub-transactions?

At first glance, it looks as if both can achieve the same result, but there must be some kind of difference, mustn't there?

Answer: This question is actually covered at large in the API documentation for the respective classes. Of course, you could write a whole book about the detailed usage of transaction phases (i.e. Transaction, Transaction groups, Sub-Transaction), if you wanted to, but the documentation already covers all the really necessary information.

Here is a brief summary:

The temporary transaction trick touch-up describes a scenario using a transaction group to enable a transaction to be committed, so the model is updated and the new state can be queried, and still enabling the whole action can be undone afterwards.

For more information on the transaction framework, please refer to Arnošt's Autodesk University presentation CP3426 Core Frameworks in the Revit API.

Response: Thank you! I use the temporary transaction trick quite a lot, so I'll definitely start using transaction groups now as well.