.NET

Reply
Active Contributor
giskumar
Posts: 44
Registered: ‎12-06-2010
Message 1 of 3 (336 Views)
Accepted Solution

Unable to open block table

336 Views, 2 Replies
12-27-2010 03:19 AM

 

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.

Just an idea, use

 DocumentLock docklock = doc. LockDocument();

using(docklock)

{

using (tr2)

{

//rest code here...

}

}

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 3 (327 Views)

Re: Unable to open block table

12-27-2010 05:32 AM in reply to: giskumar

Just an idea, use

 DocumentLock docklock = doc. LockDocument();

using(docklock)

{

using (tr2)

{

//rest code here...

}

}

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
giskumar
Posts: 44
Registered: ‎12-06-2010
Message 3 of 3 (303 Views)

Re: Unable to open block table

12-27-2010 10:30 PM in reply to: Hallex

Hi Hallex,

 

simply super

 

Now my form is working well.

 

 

Thanks,

Kumar. 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.