Community
Hi all,
I have following code to place circle with given parameters.
When i call this function from a class it is working fine.
When i call this function from button_click event it is terminating at red hilighted line.
Any help to solve this problem.
public void errcle(double rad, string lay, Point3d cnpt) { Document doc2 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db2 = doc2.Database; Editor ed2 = doc2.Editor; Transaction tr2 = db2.TransactionManager.StartTransaction(); using (tr2) { BlockTable blktb = tr2.GetObject(db2.BlockTableId, OpenMode.ForWrite) as BlockTable; BlockTableRecord blktr = tr2.GetObject(blktb[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; Circle cr = new Circle(); cr.SetDatabaseDefaults(); cr.Radius = rad; cr.Layer = lay; cr.Center = cnpt; blktr.AppendEntity(cr); tr2.AddNewlyCreatedDBObject(cr, true); tr2.Commit(); } }
thanks,
Kumar.
Solved! Go to Solution.
Solved by Hallex. Go to Solution.
Just an idea, use
DocumentLock docklock = doc. LockDocument();
using(docklock)
{
using (tr2)
{
//rest code here...
}
}