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

Removing Objects from a block definition

3 REPLIES 3
Reply
Message 1 of 4
GeeHaa
711 Views, 3 Replies

Removing Objects from a block definition

Hi,

 

I need to remove lines from a block definition and replace them with LWpolyLines. I see there is a way to Append entities to a BlockTAbleRecord but I don't see a way of removing an entity.

 

Thanks

3 REPLIES 3
Message 2 of 4
StephenPreston
in reply to: GeeHaa

Just call Erase on the Entity. And to update all the blockref graphics without having to close and reopen the DWG, you'll probably have to call RecordGraphicsModified on each BlockReference for that BlockTableRecord (remembering nested blocks too).

Cheers,

Stephen Preston
Autodesk Developer Network
Message 3 of 4
Hallex
in reply to: GeeHaa

Here is working code based on Stephen Preston's idea

Tested on 2010 with no problem, not tested on dynamic blocks though

 

        static public void SwapSubEntity()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;	

            Database db = doc.Database;	

            Editor ed = doc.Editor;	

            Transaction tr = doc.TransactionManager.StartTransaction();	

            using (tr)	

            {	

                PromptNestedEntityOptions pno = new PromptNestedEntityOptions("\nSelect Line >>");	

                pno.AllowNone = false;	

                PromptNestedEntityResult rs = ed.GetNestedEntity(pno);	

                if (rs.Status != PromptStatus.OK)	

                    return;	


                Entity selent = (Entity)tr.GetObject(rs.ObjectId, OpenMode.ForWrite);	


                BlockTableRecord btrec = tr.GetObject(selent.OwnerId, OpenMode.ForWrite) as BlockTableRecord;	


                Line ln = selent as Line;	

                if (ln != null)	

                {	

                    Autodesk.AutoCAD.DatabaseServices.Polyline pline = new Autodesk.AutoCAD.DatabaseServices.Polyline(2);	

                    pline.AddVertexAt(0, new Point2d(ln.StartPoint.X, ln.StartPoint.Y), 0, 0.05, 0.05);	

                    pline.AddVertexAt(1, new Point2d(ln.EndPoint.X, ln.EndPoint.Y), 0, 0.05, 0.05);	

                    pline.ColorIndex = 1;	

                    ObjectId plid = btrec.AppendEntity(pline);	

                    tr.AddNewlyCreatedDBObject(pline, true);	


                }	


                selent.Erase();	

                selent.Dispose();	

                doc.TransactionManager.QueueForGraphicsFlush();	

                doc.TransactionManager.FlushGraphics();	

                doc.Editor.UpdateScreen();	


                tr.Commit();	


                ed.Regen();	

            }	

        }	

 

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 4 of 4
Yehoshua18
in reply to: Hallex

Is there a way to erase objects drawn in a previous transaction?  Thanks!

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