Use Autodesk Imports with pyRevit Transaction

Yes, in the pyrevit.api module, in which you can see that it also does from Autodesk.Revit import DB; that same DB is then exposed in the pyrevit init module, so it is exactly the same thing.

The code for pyrevit’s Transaction class can be found here.
the __exit__ method is the one that is called when exiting from the context manager, and you can see that it handles the Commit if everything is good and Rollback in case of an exception, but there’s no call to Dispose.

I’m not an IronPython guru, so I don’t know if the Dispose gets magically called during the garbage collection, or if it is an overlook by our part and we should call that method on exit.

The only piece of information that I can find is that with IronPython you can use the with statement on IDisposable objects to automatically dispose them on exit (but it’s not happening here).

2 Likes