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

DgxAnnck.cs 6.3KB

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