We usually use the Transaction to open AutoCAD objects for read and write in AutoCAD .NET. However, there is also an OpenCloseTransaction and some people many wonder how to use it, why it is there, and its pros and cons.
In this article, let’s answer the first how-to question. It is pretty much the same as using Transaction in case that operation is simple enough and no extra benefits are needed except for one level reading and writing.
public static void NestedOpenCloseTransaction_Method()
Database db = HostApplicationServices.WorkingDatabase;
using (OpenCloseTransaction tr = db.TransactionManager.StartOpenCloseTransaction())
Entity lastEnt = (Entity)tr.GetObject(Autodesk.AutoCAD.Internal.Utils.EntLast(), OpenMode.ForWrite);
lastEnt.ColorIndex = 1;
catch (System.Exception ex)
We will be talking about why it is there in the next post.
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) provides various project wizards, item wizards, coders and widgets to help program AutoCAD .NET addins.