工具箱相关
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.

CheckContourLine.cs 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. using GrxCAD.Geometry;
  10. namespace HCTools
  11. {
  12. class CheckContourLine
  13. {
  14. public static int gap;
  15. public static string jqx;
  16. public static string sqx;
  17. public void Valuecheck()
  18. {
  19. Document doc = Application.DocumentManager.MdiActiveDocument;
  20. string LayerName = jqx + "," +sqx;
  21. ObjectId[] ids = BasicFunction.getHeight(LayerName);//存放获取的等高线id
  22. //如果没有等高线则返回
  23. if (ids == null)
  24. return;
  25. //检查是否有错误曲线图层,没有则创建
  26. LayerControl layerscontrol = new LayerControl();
  27. string layname = "等高线有误";
  28. if (!layerscontrol.haslayername(layname))
  29. {
  30. colorgb col = new colorgb(255, 0, 225);
  31. layerscontrol.creatlayer(layname, col);
  32. layerscontrol.movelayertofront(layname);
  33. }
  34. else
  35. layerscontrol.movelayertofront(layname);
  36. int j = 0;
  37. int num = 0;
  38. for (int i = 0; i < ids.Length; i++)
  39. {
  40. Polyline pll = BasicFunction.GetDBObject(ids[i]) as Polyline;
  41. if (pll.Elevation <= 0)
  42. {
  43. ChangeLayer(pll.Id, layname);
  44. j++;
  45. }
  46. else
  47. {
  48. if (int.TryParse(Math.Round(pll.Elevation, 3, MidpointRounding.AwayFromZero).ToString(), out num))
  49. {
  50. if (Math.Round(pll.Elevation,3, MidpointRounding.AwayFromZero) % gap == 0)
  51. {
  52. continue;
  53. }
  54. else
  55. {
  56. ChangeLayer(pll.Id, layname);
  57. j++;
  58. }
  59. }
  60. else
  61. {
  62. ChangeLayer(pll.Id, layname);
  63. j++;
  64. }
  65. }
  66. }
  67. Editor ed = doc.Editor; ed.WriteMessage("共有" + j + "处错误");
  68. }
  69. private void ChangeLayer(ObjectId c1Id, string lyname)
  70. {
  71. Database db = HostApplicationServices.WorkingDatabase;
  72. DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  73. using (Transaction trans = db.TransactionManager.StartTransaction())
  74. {
  75. BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
  76. BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  77. Entity ent1 = (Entity)c1Id.GetObject(OpenMode.ForWrite);
  78. ent1.Layer = lyname;
  79. trans.Commit();
  80. }
  81. doclock.Dispose();
  82. }
  83. }
  84. }