By Barbara Han
For programmers who used ObjectARX before, they understand how transactions work in ObjectARX, but may be wondering how nested transactions suppose to work in Inventor in general.
The following is a summary of how transactions are suppose to work in Inventor:
The Inventor ActiveX API's implementation of nested transactions is based on the Inventor's internal architecture.
1. In Inventor's COM API, transactions are represented by the Transaction object. Transaction objects are managed by the TransactionManager object. You can start a transaction by calling TransactionManager.StartTransaction. To end a transaction, call TransactionManager.EndTransaction. You can abort a transaction before it ends by calling TransactionManager.AbortTransaction.
You can nest transactions by starting/ending another transaction within a scope of another starting/ending transaction.
TransactionManager.StartTransaction // T1
TransactionManager.StartTransaction // child of T1
TransactionManager.EndTransaction // child of T1
TransactionManager.EndTransaction // T1
However, you can't overlap one starting/ending loop with another one.
TransactionManager.StartTransaction // T1
TransactionManager.StartTransaction // child of T1
TransactionManager.EndTransaction // T1
TransactionManager.EndTransaction // child of T1
The above is wrong.
Refer to the Inventor COM API documentation for more details on Transaction and TransactionManager objects.
2. Undo will undo all nested transactions up to the parent transaction (the top level transaction). Inventor internal architecture only supports such a behavior so the API is reflecting it. So in this sense it will not be transaction UNDO API feature mirrors the AutoCAD implementation. Inventor and AutoCAD function differently.
3. Calling undo transaction on the current top parent transaction will cause an undo only if the transaction is committed. The next committed top level transaction in the stack would then automatically be eligible for the next TransactionManager.UndoTransaction call.
4. When you have nested transactions, you can use CheckPoints to control the level of aborting before transactions are committed. To set a CheckPoint, call TransactionManager.SetCheckPoint(). When you abort, it will roll back to the last available CheckPoint or a specified one. If there is none, it will roll back to the parent transaction. This is generally true but may vary based on where you set your CheckPoint and how you nest your transactions.
TransactionManager.StartTransaction // T1 - parent
TransactionManager.StartTransaction // child 1 of T1
TransactionManager.SetCheckPoint // check point for child 1
TransactionManager.EndTransaction // child 1 of T1
TransactionManager.StartTransaction // child 2 of T1
TransactionManager.SetCheckPoint // check point for child 2
TransactionManager.EndTransaction // child 2 of T1
TransactionManager.EndTransaction // T1
5. Currently you can only abort nested child transactions. Parent transactions can only be undo/redo.
ChangeProcessor interface also support undo actions. Please look at Inventor API help document for more details. There are also some related blog articles:
How to Undo or Abort ChangeProcessor
Is there a way to purge all the unreferenced documents in Inventor ?