using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using GrxCAD.ApplicationServices; using GrxCAD.DatabaseServices; using GrxCAD.EditorInput; namespace HCTools { class Hierarchy { public static int gap;//等高距 public static string CrtLayerName;//当前等高线所在图层 /// /// 等高线分层 /// public void hierarchy() { ObjectId[] ids = BasicFunction.getHeight(CrtLayerName);//存放获取的等高线id //检查是否有计曲线图层,没有则创建 LayerControl layerscontrol = new LayerControl(); string Jilayname = "8120"; if (!layerscontrol.haslayername(Jilayname)) { colorgb col = new colorgb(255, 255, 0); layerscontrol.creatlayer(Jilayname, col); layerscontrol.movelayertofront(Jilayname); } else layerscontrol.movelayertofront(Jilayname); //检查是否有首曲线图层,没有则创建 LayerControl layerscontrol1 = new LayerControl(); string Shoulayname = "8110"; if (!layerscontrol1.haslayername(Shoulayname)) { colorgb col = new colorgb(0, 0, 0); layerscontrol1.creatlayer(Shoulayname, col); layerscontrol1.movelayertofront(Shoulayname); } else layerscontrol1.movelayertofront(Shoulayname); if (ids == null) return; for (int i = 0; i < ids.Length; i++) { Polyline pll = BasicFunction.GetDBObject(ids[i]) as Polyline; if (Math.Round(pll.Elevation, 7, MidpointRounding.AwayFromZero) % (gap * 5) == 0 && pll.Layer != "8120") { ChangeLayer(pll.Id, Jilayname); } if (Math.Round(pll.Elevation, 7, MidpointRounding.AwayFromZero) % (gap * 5) != 0 && pll.Layer != "8110") { ChangeLayer(pll.Id, Shoulayname); } else continue; } } /// /// 将计曲线移动到相应图层 /// private void ChangeLayer(ObjectId c1Id, string LayerName) { Database db = HostApplicationServices.WorkingDatabase; DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); using (Transaction trans = db.TransactionManager.StartTransaction()) { BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); Entity ent1 = (Entity)c1Id.GetObject(OpenMode.ForWrite); ent1.Layer = LayerName; trans.Commit(); } doclock.Dispose(); } } }