Transaction.Commit throws exception

By Adam Nagy

Unlike in vanilla AutoCAD, in AutoCAD Mechanical each command is automatically wrapped in a Transaction. You can verify this by checking the value of Database.TransactionManager.TopTransaction inside your command – in case of AutoCAD Mechanical it will be an object with type AppTransaction:

AppTransaction

When using the PlotEngine in your code to publish a drawing and creating your own Transaction to open the necessary objects, it seems to get entangled with AppTransaction. As a result you get an exception "Operation is not valid due to the current state of the object." when calling Transaction.Commit() at the end of your command:

TrCommit

There seems to be two workarounds: either just use the already available AppTransaction inside AutoCAD Mechanical to open the objects you need (not sure if that could have some side effects) or use an OpenCloseTransaction instead of a normal Transaction, by calling StartOpenCloseTransaction():

StartOpenCloseTransaction

 


Comments

One response to “Transaction.Commit throws exception”

  1. good tips when using this tools

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading