Community
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
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).
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(); } }
Is there a way to erase objects drawn in a previous transaction? Thanks!