static public void transformToTunnel() { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; PromptSelectionResult res = ed.SelectAll(); if (res.Status == PromptStatus.Error) { return; } Autodesk.AutoCAD.EditorInput.SelectionSet SS = res.Value; var tmpidarray = SS.GetObjectIds(); var idArray = SS.GetObjectIds(); Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager; List <DBTunnel> inList = new List <DBTunnel>(); Utils.TransactionControl(() => { foreach (ObjectId id in tmpidarray) { Entity entity = (Entity)tm.GetObject(id, OpenMode.ForWrite, true); if (!(entity is Line) && !(entity is Autodesk.AutoCAD.DatabaseServices.Polyline)) { continue; } if (entity is Line) { Line line = entity as Line; DBTunnel dbTunnel = new DBTunnel(); dbTunnel.BasePoints = new List <DBVertice> { new DBVertice(line.StartPoint), new DBVertice(line.EndPoint) }; inList.Add(dbTunnel); line.Erase(); } else if (entity is Autodesk.AutoCAD.DatabaseServices.Polyline) { Autodesk.AutoCAD.DatabaseServices.Polyline polyline = entity as Autodesk.AutoCAD.DatabaseServices.Polyline; DBTunnel dbTunnel = new DBTunnel(); dbTunnel.BasePoints = new List <DBVertice>(); for (int i = 0; i < polyline.NumberOfVertices; i++) { dbTunnel.BasePoints.Add(new DBVertice(polyline.GetPoint3dAt(i))); } if (polyline.Closed == true) { dbTunnel.IsClosed = true; } inList.Add(dbTunnel); polyline.Erase(); } } }); var resList = DrawTunnel.StaticDrawSquareTunnel(inList); }