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

Creating blocks, but not inserting correctly

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
tommam
655 Views, 3 Replies

Creating blocks, but not inserting correctly

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();

                }

            }

3 REPLIES 3
Message 2 of 4
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 4
DiningPhilosopher
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.

 

 

Message 4 of 4
tommam
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!

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