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

EleptDenck.cs 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using GrxCAD.ApplicationServices;
  2. using GrxCAD.DatabaseServices;
  3. using GrxCAD.EditorInput;
  4. using GrxCAD.Geometry;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace HCTools
  11. {
  12. class EleptDenck
  13. {
  14. public static string ptlayer;
  15. public static string tklayer;
  16. public static double density;
  17. public static int flag;
  18. public void Ptdensity()
  19. {
  20. ObjectId[] ids = TKget();
  21. Database db = HostApplicationServices.WorkingDatabase;
  22. DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  23. Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  24. TypedValue[] typedvalue = new TypedValue[2];
  25. typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, ptlayer), 0);
  26. typedvalue.SetValue(new TypedValue((int)DxfCode.Start, "Insert"), 1);
  27. SelectionFilter selectionfilter = new SelectionFilter(typedvalue);
  28. for (int i = 0; i < ids.Length; i++)
  29. {
  30. Entity current_entity = BasicFunction.GetDBObject(ids[i]);
  31. ZoomToExtent(current_entity.GeometricExtents);
  32. using (Transaction trans = db.TransactionManager.StartTransaction())
  33. {
  34. Polyline pll = (Polyline)trans.GetObject(ids[i], OpenMode.ForWrite);
  35. Point3dCollection ptcoll = new Point3dCollection();
  36. for (int j = 0; j < pll.NumberOfVertices; j++)
  37. {
  38. ptcoll.Add(pll.GetPoint3dAt(j));
  39. }
  40. PromptSelectionResult psr = editor.SelectCrossingPolygon(ptcoll,selectionfilter);
  41. if (psr.Status == PromptStatus.OK)
  42. {
  43. SelectionSet selectionset = psr.Value;
  44. int ptnums = selectionset.Count;
  45. double den = ptnums / pll.Area;
  46. if (den < density && flag == 1)
  47. {
  48. LayerControl layerscontrol = new LayerControl();
  49. string layname = "小于密度";
  50. if (!layerscontrol.haslayername(layname))
  51. {
  52. colorgb col = new colorgb(255, 0, 0);
  53. layerscontrol.creatlayer(layname, col);
  54. pll.Layer = "小于密度";
  55. }
  56. else
  57. pll.Layer = "小于密度";
  58. //pll.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  59. }
  60. else if (den > density && flag == 2)
  61. {
  62. LayerControl layerscontrol = new LayerControl();
  63. string layname = "大于密度";
  64. if (!layerscontrol.haslayername(layname))
  65. {
  66. colorgb col = new colorgb(255, 0, 0);
  67. layerscontrol.creatlayer(layname, col);
  68. pll.Layer = "大于密度";
  69. }
  70. else
  71. pll.Layer = "大于密度";
  72. //pll.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  73. }
  74. else if (flag == 3)
  75. {
  76. if (den < density || den > density)
  77. {
  78. LayerControl layerscontrol = new LayerControl();
  79. string layname = "不等于密度";
  80. if (!layerscontrol.haslayername(layname))
  81. {
  82. colorgb col = new colorgb(255, 0, 0);
  83. layerscontrol.creatlayer(layname, col);
  84. pll.Layer = "不等于密度";
  85. }
  86. else
  87. pll.Layer = "不等于密度";
  88. //pll.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  89. }
  90. }
  91. }
  92. trans.Commit();
  93. }
  94. }
  95. doclock.Dispose();
  96. }
  97. private static ObjectId[] TKget()
  98. {
  99. Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  100. TypedValue[] typedvalue = new TypedValue[1];
  101. typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, tklayer), 0);
  102. SelectionFilter selectionfilter = new SelectionFilter(typedvalue);
  103. PromptSelectionResult psr = editor.SelectAll(selectionfilter);
  104. SelectionSet selectionset = psr.Value;
  105. ObjectId[] obj = new ObjectId[selectionset.Count];
  106. if (psr.Status == PromptStatus.OK)
  107. {
  108. obj = selectionset.GetObjectIds();
  109. }
  110. return obj;
  111. }
  112. public static void ZoomToExtent(Extents3d extent)
  113. {
  114. try
  115. {
  116. Point3d pMin = extent.MinPoint;
  117. Point3d pMax = extent.MaxPoint;
  118. //获取当前文档及数据库
  119. Document acDoc = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  120. Database acCurDb = acDoc.Database;
  121. // 启动事务
  122. using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
  123. {
  124. using (ViewTableRecord acView = acDoc.Editor.GetCurrentView())
  125. {
  126. //设置视图的高
  127. acView.Height = Math.Abs(pMin.Y - pMax.Y);
  128. //设置视图的宽
  129. acView.Width = Math.Abs(pMin.X - pMax.X);
  130. // 设置视图中心
  131. acView.CenterPoint = new Point2d((pMin.X + pMax.X) / 2, (pMin.Y + pMax.Y) / 2);
  132. // 更新当前视图
  133. acDoc.Editor.SetCurrentView(acView);
  134. }
  135. // 提交更改
  136. acTrans.Commit();
  137. }
  138. }
  139. catch (Exception)
  140. {
  141. throw;
  142. }
  143. }
  144. }
  145. }