.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unable to open block table

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
giskumar
633 Views, 2 Replies

Unable to open block table

 

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.

2 REPLIES 2
Message 2 of 3
Hallex
in reply to: giskumar

Just an idea, use

 DocumentLock docklock = doc. LockDocument();

using(docklock)

{

using (tr2)

{

//rest code here...

}

}

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 3
giskumar
in reply to: Hallex

Hi Hallex,

 

simply super

 

Now my form is working well.

 

 

Thanks,

Kumar. 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost