工具箱相关
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Hierarchy.cs 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using GrxCAD.ApplicationServices;
  7. using GrxCAD.DatabaseServices;
  8. using GrxCAD.EditorInput;
  9. namespace HCTools
  10. {
  11. class Hierarchy
  12. {
  13. public static int gap;//等高距
  14. public static string CrtLayerName;//当前等高线所在图层
  15. /// <summary>
  16. /// 等高线分层
  17. /// </summary>
  18. public void hierarchy()
  19. {
  20. ObjectId[] ids = BasicFunction.getHeight(CrtLayerName);//存放获取的等高线id
  21. //检查是否有计曲线图层,没有则创建
  22. LayerControl layerscontrol = new LayerControl();
  23. string Jilayname = "8120";
  24. if (!layerscontrol.haslayername(Jilayname))
  25. {
  26. colorgb col = new colorgb(255, 255, 0);
  27. layerscontrol.creatlayer(Jilayname, col);
  28. layerscontrol.movelayertofront(Jilayname);
  29. }
  30. else
  31. layerscontrol.movelayertofront(Jilayname);
  32. //检查是否有首曲线图层,没有则创建
  33. LayerControl layerscontrol1 = new LayerControl();
  34. string Shoulayname = "8110";
  35. if (!layerscontrol1.haslayername(Shoulayname))
  36. {
  37. colorgb col = new colorgb(0, 0, 0);
  38. layerscontrol1.creatlayer(Shoulayname, col);
  39. layerscontrol1.movelayertofront(Shoulayname);
  40. }
  41. else
  42. layerscontrol1.movelayertofront(Shoulayname);
  43. if (ids == null)
  44. return;
  45. for (int i = 0; i < ids.Length; i++)
  46. {
  47. Polyline pll = BasicFunction.GetDBObject(ids[i]) as Polyline;
  48. if (Math.Round(pll.Elevation, 7, MidpointRounding.AwayFromZero) % (gap * 5) == 0 && pll.Layer != "8120")
  49. {
  50. ChangeLayer(pll.Id, Jilayname);
  51. }
  52. if (Math.Round(pll.Elevation, 7, MidpointRounding.AwayFromZero) % (gap * 5) != 0 && pll.Layer != "8110")
  53. {
  54. ChangeLayer(pll.Id, Shoulayname);
  55. }
  56. else
  57. continue;
  58. }
  59. }
  60. /// <summary>
  61. /// 将计曲线移动到相应图层
  62. /// </summary>
  63. private void ChangeLayer(ObjectId c1Id, string LayerName)
  64. {
  65. Database db = HostApplicationServices.WorkingDatabase;
  66. DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  67. using (Transaction trans = db.TransactionManager.StartTransaction())
  68. {
  69. BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
  70. BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  71. Entity ent1 = (Entity)c1Id.GetObject(OpenMode.ForWrite);
  72. ent1.Layer = LayerName;
  73. trans.Commit();
  74. }
  75. doclock.Dispose();
  76. }
  77. }
  78. }