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

DGXGeneralization.cs 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using GrxCAD.ApplicationServices;
  2. using GrxCAD.DatabaseServices;
  3. using GrxCAD.EditorInput;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace HCTools
  12. {
  13. class DGXGeneralization
  14. {
  15. public static ArrayList dgxlayerlist;
  16. public static double dgj;
  17. public static bool openflag = true;
  18. public static void dgxGeneralization()
  19. {
  20. Document doc = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  21. Database db = doc.Database;
  22. DocumentLock docLock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  23. //try
  24. //{
  25. //LayerTable lt = null;
  26. //ArrayList layerlist = new ArrayList();
  27. ////获取图层事务
  28. //using (Transaction tran = doc.TransactionManager.StartTransaction())
  29. //{
  30. // lt = tran.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
  31. // foreach (ObjectId layerid in lt)
  32. // {
  33. // LayerTableRecord ltrec = tran.GetObject(layerid, OpenMode.ForWrite) as LayerTableRecord;
  34. // layerlist.Add(ltrec.Name);
  35. // }
  36. // doc.Editor.WriteMessage("程序开始运行\r\n......\r\n");
  37. // tran.Commit();
  38. // tran.Dispose();
  39. //}
  40. //DGXSBForm sf = new DGXSBForm(layerlist);
  41. //if (sf.ShowDialog() == DialogResult.OK)
  42. //{
  43. // dgxlayerlist = sf.DGXlayerlist;
  44. // dgj = sf.DGJ;
  45. // openflag = true;
  46. //}
  47. if (openflag)
  48. {
  49. string dgx1 = string.Empty, dgx2 = string.Empty;
  50. if (dgxlayerlist.Count > 0)
  51. {
  52. if (dgxlayerlist.Count == 1)
  53. {
  54. dgx1 = dgxlayerlist[0].ToString();
  55. }
  56. if (dgxlayerlist.Count == 2)
  57. {
  58. dgx1 = dgxlayerlist[0].ToString();
  59. dgx2 = dgxlayerlist[1].ToString();
  60. }
  61. }
  62. using (Transaction tran = doc.TransactionManager.StartTransaction())
  63. {
  64. //// 以只读方式打开块表记录 Open the Block table record for read
  65. BlockTable acbt = tran.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
  66. //// 以写方式打开模型空间块表记录 Open the Block table record Model space for write
  67. BlockTableRecord acblr = tran.GetObject(acbt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
  68. //设置激活图层
  69. LayerTable layertable = tran.GetObject(db.LayerTableId, OpenMode.ForWrite) as LayerTable;
  70. if (!layertable.Has("Delete"))
  71. {
  72. LayerTableRecord ltr = new LayerTableRecord();
  73. ltr.Name = "Delete";
  74. ObjectId layerid = layertable.Add(ltr);
  75. tran.AddNewlyCreatedDBObject(ltr, true);
  76. //db.Clayer = layerid;
  77. }
  78. if (!layertable.Has("8120"))
  79. {
  80. LayerTableRecord ltr = new LayerTableRecord();
  81. ltr.Name = "8120";
  82. ObjectId layerid = layertable.Add(ltr);
  83. tran.AddNewlyCreatedDBObject(ltr, true);
  84. //db.Clayer = layerid;
  85. }
  86. if (!layertable.Has("8110"))
  87. {
  88. LayerTableRecord ltr = new LayerTableRecord();
  89. ltr.Name = "8110";
  90. ObjectId layerid = layertable.Add(ltr);
  91. tran.AddNewlyCreatedDBObject(ltr, true);
  92. //db.Clayer = layerid;
  93. }
  94. tran.Commit();
  95. tran.Dispose();
  96. }
  97. PromptSelectionResult psr = doc.Editor.SelectAll();
  98. //doc.Editor.WriteMessage("请选择等高线!");
  99. //PromptSelectionResult psr = doc.Editor.GetSelection();
  100. if (psr.Status == PromptStatus.OK)
  101. {
  102. SelectionSet ss = psr.Value;
  103. foreach (ObjectId oid in ss.GetObjectIds())
  104. {
  105. using (Transaction tran = doc.TransactionManager.StartTransaction())
  106. {
  107. BlockTable acbt = tran.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
  108. BlockTableRecord acbtr = tran.GetObject(acbt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
  109. Entity en = tran.GetObject(oid, OpenMode.ForWrite) as Entity;
  110. if ((en.Layer == dgx1) || (en.Layer == dgx2))
  111. {
  112. Polyline pl = new Polyline();
  113. Polyline2d pl2d = new Polyline2d();
  114. double elevation = 99999999;
  115. if (en is Polyline)
  116. {
  117. pl = en as Polyline;
  118. elevation = pl.Elevation;
  119. }
  120. else if (en is Polyline2d)
  121. {
  122. pl2d = en as Polyline2d;
  123. elevation = pl2d.Elevation;
  124. }
  125. if (elevation != 99999999)
  126. {
  127. elevation = Convert.ToDouble(elevation.ToString("f1"));
  128. if (dgj != 0)
  129. {
  130. double remainder = elevation % dgj;
  131. if (remainder != 0.0)
  132. {
  133. en.Layer = "Delete";
  134. en.Color = GrxCAD.Colors.Color.FromColor(System.Drawing.Color.Red);
  135. }
  136. else
  137. {
  138. double remainder2 = elevation % (dgj * 5);
  139. if (remainder2 == 0.0)
  140. {
  141. en.Layer = "8120";
  142. en.Color = GrxCAD.Colors.Color.FromColor(System.Drawing.Color.Yellow);
  143. }
  144. else
  145. {
  146. en.Layer = "8110";
  147. en.Color = GrxCAD.Colors.Color.FromColor(System.Drawing.Color.White);
  148. }
  149. }
  150. }
  151. }
  152. }
  153. else
  154. continue;
  155. //
  156. tran.Commit();
  157. tran.Dispose();
  158. }
  159. }
  160. doc.Editor.WriteMessage("程序运行结束,谢谢使用");
  161. }
  162. }
  163. else
  164. {
  165. doc.Editor.WriteMessage("请选择相关参数\r\n");
  166. }
  167. //}
  168. //catch (GrxCAD.Runtime.Exception ex)
  169. //{
  170. // doc.Editor.WriteMessage(ex.ToString());
  171. //}
  172. docLock.Dispose();
  173. }
  174. }
  175. }