工具箱相关
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DeletePts.cs 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 DeletePts
  13. {
  14. public static string gcdly;//高程点所在图层
  15. public static List<string> delely = new List<string>();//需要删除的图层
  16. public static int blc;//比例尺
  17. public double radius;//半径
  18. public void delept()
  19. {
  20. List<ObjectId> deleids = new List<ObjectId>();
  21. if (blc == 500)
  22. {
  23. radius = 1.5;
  24. }
  25. else if (blc == 1000)
  26. {
  27. radius = 2.5;
  28. }
  29. else if (blc == 2000)
  30. {
  31. radius = 4;
  32. }
  33. else if (blc == 5000)
  34. {
  35. radius = 10.5;
  36. }
  37. //创建新图层
  38. LayerControl layerscontrol = new LayerControl();
  39. string layname = "已删除";
  40. if (!layerscontrol.haslayername(layname))
  41. {
  42. colorgb col = new colorgb(255, 0, 255);
  43. layerscontrol.creatlayer(layname, col);
  44. layerscontrol.movelayertofront(layname);
  45. }
  46. else
  47. layerscontrol.movelayertofront(layname);
  48. for (int i = 0; i < delely.Count; i++)
  49. {
  50. List<ObjectId> temp = Idget(delely[i]);
  51. for (int j = 0; j < temp.Count; j++)
  52. {
  53. deleids.Add(temp[j]);
  54. }
  55. }
  56. Database db = HostApplicationServices.WorkingDatabase;
  57. DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  58. Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  59. TypedValue[] typedvalue = new TypedValue[]
  60. {
  61. new TypedValue((int)DxfCode.LayerName, gcdly),
  62. new TypedValue((int)DxfCode.Start, "Insert")
  63. };
  64. SelectionFilter selectionfilter = new SelectionFilter(typedvalue);
  65. for (int i = 0; i < deleids.Count; i++)
  66. {
  67. using (Transaction trans = db.TransactionManager.StartTransaction())
  68. {
  69. Entity ent = (Entity)trans.GetObject(deleids[i], OpenMode.ForWrite);
  70. if (ent is Polyline)
  71. {
  72. Polyline pll = (Polyline)trans.GetObject(deleids[i], OpenMode.ForWrite);
  73. Point3dCollection ptcoll = new Point3dCollection();
  74. for (int j = 0; j < pll.NumberOfVertices; j++)
  75. {
  76. ptcoll.Add(pll.GetPoint3dAt(j));
  77. }
  78. PromptSelectionResult psr = editor.SelectCrossingPolygon(ptcoll, selectionfilter);
  79. if (psr.Status == PromptStatus.OK)
  80. {
  81. SelectionSet selectionset = psr.Value;
  82. ObjectId[] ids = selectionset.GetObjectIds();
  83. for (int j = 0; j < ids.Count(); j++)
  84. {
  85. BlockReference br = (BlockReference)trans.GetObject(ids[j], OpenMode.ForWrite);
  86. br.Layer = "已删除";
  87. Point3d p1 = new Point3d(br.Position.X - radius, br.Position.Y - radius, 0);
  88. Point3d p2 = new Point3d(br.Position.X + radius, br.Position.Y + radius, 0);
  89. TypedValue[] tpvl = new TypedValue[]
  90. {
  91. new TypedValue((int)DxfCode.Start, "Text"),
  92. new TypedValue((int)DxfCode.LayerName, gcdly)
  93. };
  94. SelectionFilter filter = new SelectionFilter(tpvl);
  95. PromptSelectionResult prosr = editor.SelectCrossingWindow(p1, p2, filter);
  96. if (prosr.Status == PromptStatus.OK)
  97. {
  98. SelectionSet seleset = prosr.Value;
  99. ObjectId[] selid = seleset.GetObjectIds();
  100. for (int ii = 0; ii < selid.Count(); ii++)
  101. {
  102. DBText text = trans.GetObject(selid[ii], OpenMode.ForWrite) as DBText;
  103. text.Layer = "已删除";
  104. }
  105. }
  106. }
  107. }
  108. trans.Commit();
  109. }
  110. }
  111. }
  112. editor.WriteMessage("删除完成\n");
  113. doclock.Dispose();
  114. }
  115. private static List<ObjectId> Idget(string ly)
  116. {
  117. Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  118. TypedValue[] typedvalue = new TypedValue[1];
  119. typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, ly), 0);
  120. SelectionFilter selectionfilter = new SelectionFilter(typedvalue);
  121. PromptSelectionResult psr = editor.SelectAll(selectionfilter);
  122. SelectionSet selectionset = psr.Value;
  123. ObjectId[] obj = new ObjectId[selectionset.Count];
  124. List<ObjectId> ids = new List<ObjectId>();
  125. if (psr.Status == PromptStatus.OK)
  126. {
  127. obj = selectionset.GetObjectIds();
  128. for (int i = 0; i < obj.Length; i++)
  129. {
  130. ids.Add(obj[i]);
  131. }
  132. }
  133. return ids;
  134. }
  135. }
  136. }