Polyline2d ClonePolyline2d(Polyline2d oldEnt) { try { Point3dCollection vertices = new Point3dCollection(); DoubleCollection bulges = new DoubleCollection();; IEnumerator Enumerator = oldEnt.GetEnumerator(); while (Enumerator.MoveNext()) { ObjectId id = (ObjectId)Enumerator.Current; Vertex2d vtx = (Vertex2d)id.GetObject(OpenMode.ForWrite); vertices.Add(vtx.Position); bulges.Add(vtx.Bulge); vtx.Dispose(); } return(new Polyline2d(oldEnt.PolyType, vertices, oldEnt.Elevation, oldEnt.Closed, oldEnt.DefaultStartWidth, oldEnt.DefaultEndWidth, bulges)); } catch (Exception ex) { Logger.log("ClonePolyline2d", ex.Message); } return(null); }
public static void ObjectsByLayer() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Transaction tr = db.TransactionManager.StartTransaction(); string output = Path.ChangeExtension(doc.Name, "dat"); if (doc == null) { return; } var ed = doc.Editor; // Select the objects to sort // Setups the keyword options PromptSelectionOptions Opts = new PromptSelectionOptions(); Opts.MessageForAdding = "\n请选择断面图"; var psr = ed.GetSelection(Opts); if (psr.Status != PromptStatus.OK) { return; } // We'll sort them based on a string value (the layer name) var map = new Dictionary <ObjectId, string>(); foreach (dynamic id in psr.Value.GetObjectIds()) { if (id.ObjectClass.Name == "AcDbText") { if (id.TextString.Contains("K")) { map.Add(id, id.TextString); WriteMessage(output, id.TextString); } else if (id.TextString.Contains("Wy")) { WriteMessage(output, "#------------------------------------------------------#"); map.Add(id, id.TextString); WriteMessage(output, id.TextString); } if (id.Layer == "右标高1") { map.Add(id, id.TextString); WriteMessage(output, "H0=" + id.TextString); } else if (id.Layer == "左标高") { map.Add(id, id.TextString); WriteMessage(output, "H1=" + id.TextString); } else if (id.Layer == "左标高1") { map.Add(id, id.TextString); WriteMessage(output, "H2=" + id.TextString); } } else if (id.ObjectClass.Name == "AcDb2dPolyline") { Polyline2d tmp = (Polyline2d)tr.GetObject(id, OpenMode.ForRead); // tmp. if (tmp.Layer == "dmx") { WriteMessage(output, "dmx"); IEnumerator vertices = tmp.GetEnumerator(); while (vertices.MoveNext()) { ObjectId vetxid = (ObjectId)vertices.Current; Vertex2d vtx = (Vertex2d)vetxid.GetObject(OpenMode.ForRead); string loc = string.Format("{0},{1},0", vtx.Position.X, vtx.Position.Y); WriteMessage(output, loc); } } else if (tmp.Layer == "sjx") { WriteMessage(output, "sjx"); IEnumerator vertices = tmp.GetEnumerator(); while (vertices.MoveNext()) { ObjectId vetxid = (ObjectId)vertices.Current; Vertex2d vtx = (Vertex2d)vetxid.GetObject(OpenMode.ForRead); string loc = string.Format("{0},{1},0", vtx.Position.X, vtx.Position.Y); WriteMessage(output, loc); } } } else if (id.ObjectClass.Name == "AcDbLine") { Line zx = (Line)tr.GetObject(id, OpenMode.ForRead); if (zx.Layer == "zhix") { WriteMessage(output, "X=" + zx.StartPoint.X.ToString()); } } } var sorted = map.OrderBy(kv => kv.Value); // Print them in order to the command-line foreach (var item in sorted) { ed.WriteMessage("\nObject {0} on layer {1}", item.Key, item.Value); } tr.Commit(); tr.Dispose(); }