.NET

.NET

Reply
Distinguished Contributor
tommam
Posts: 139
Registered: ‎05-07-2008
Message 1 of 4 (316 Views)
Accepted Solution

Creating blocks, but not inserting correctly

316 Views, 3 Replies
03-22-2013 03:34 PM

I use the following code to create blocks in AutoCAD 2013.  When the user goes to insert this block, the insert command does not show a preview of the block when moving the mouse to locate it, and it comes in exploded.  This was working at one point, but something changed.  Is there some setting in AutoCAD or through the API that would cause this behavior?  Any other ideas?

 

Thanks!!

 

            Document doc = Application.DocumentManager.MdiActiveDocument;

            Database db = doc.Database;

 

            Point3d p1 = new Point3d(0, 0, 0);

            Point3d p2 = new Point3d(10, 0, 0);

            Point3d p3 = new Point3d(10, 10, 0);

 

            using (Transaction Tx = db.TransactionManager.StartTransaction())

            {

                BlockTable blkTbl = Tx.GetObject(db.BlockTableId, OpenMode.ForRead, false, true) as BlockTable;

 

                if (blkTbl.Has("TEST"))

                {

                    // ...Warn the user

                }

                else

                {

                    BlockTableRecord btr = new BlockTableRecord();

                    btr.Name = "TEST";

 

                    blkTbl.UpgradeOpen();

                    ObjectId btrId = blkTbl.Add(btr);

                    Tx.AddNewlyCreatedDBObject(btr, true);

 

                    // Add entities

                    Line l1 = new Line(p1, p2);

                    l1.ColorIndex = 5;

                    btr.AppendEntity(l1);

                    Tx.AddNewlyCreatedDBObject(l1, true);

                    Line l2 = new Line(p2, p3);

                    l2.ColorIndex = 5;

                    btr.AppendEntity(l2);

                    Tx.AddNewlyCreatedDBObject(l2, true);

 

                    Tx.Commit();

                }

            }

Blocks created by your plugin/extension do not get a preview icon automatically. You would need to use the BLOCKICON command or some other means of generating the preview icon.

 

As far as being inserted exploded, that's most-likely because the checkbox on the insert dialog is checked.

 

 

*Expert Elite*
Alfred.NESWADBA
Posts: 9,581
Registered: ‎06-29-2007
Message 2 of 4 (300 Views)

Re: Creating blocks, but not inserting correctly

03-22-2013 04:23 PM in reply to: tommam

Hi,

 

>> to insert this block, the insert command does not show a preview

>> [...] and it comes in exploded

this code shows how you create a blockdefinition, it does not show how the user is inserting anything with preview or exploded.

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 3 of 4 (289 Views)

Re: Creating blocks, but not inserting correctly

03-22-2013 07:50 PM in reply to: tommam

Blocks created by your plugin/extension do not get a preview icon automatically. You would need to use the BLOCKICON command or some other means of generating the preview icon.

 

As far as being inserted exploded, that's most-likely because the checkbox on the insert dialog is checked.

 

 

Distinguished Contributor
tommam
Posts: 139
Registered: ‎05-07-2008
Message 4 of 4 (268 Views)

Re: Creating blocks, but not inserting correctly

03-23-2013 07:51 AM in reply to: DiningPhilosopher

Yes, somehow the "Explode" checkbox got checked.  That took care of the preview also.  Now, when the user inserts, they see the preview and the block does not explode.  Don't I feel foolish!

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.