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

EleRound.cs 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using GrxCAD.DatabaseServices;
  2. using GrxCAD.Geometry;
  3. using GrxCAD.ApplicationServices;
  4. using GrxCAD.EditorInput;
  5. using System.Windows.Forms;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace HCTools
  12. {
  13. class EleRound
  14. {
  15. public static string jqx;
  16. public static string sqx;
  17. public void eleround()
  18. {
  19. Database db = HostApplicationServices.WorkingDatabase;
  20. Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  21. string lyrname = jqx + "," + sqx;
  22. //选择要取整等高线
  23. TypedValue[] value = new TypedValue[]
  24. {
  25. new TypedValue((int)DxfCode.LayerName,lyrname),
  26. new TypedValue((int)DxfCode.Start,"LWPOLYLINE")
  27. };//设置筛选条件
  28. SelectionFilter filter = new SelectionFilter(value);//选择区域中全部对象
  29. //PromptSelectionResult psr = ed.SelectAll(filter);// 要求在图形区域中手动选择对象
  30. PromptSelectionResult psr = ed.GetSelection(filter);
  31. if (psr.Status == PromptStatus.OK)
  32. {
  33. int elelines = 0;
  34. SelectionSet ss = psr.Value;
  35. if (ss == null)
  36. return;
  37. ObjectIdCollection idcoll1 = new ObjectIdCollection(ss.GetObjectIds());
  38. for (int i = 0; i < idcoll1.Count; i++)
  39. {
  40. DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  41. using (Transaction trans = db.TransactionManager.StartTransaction())
  42. {
  43. BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
  44. BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  45. Polyline pll = (Polyline)idcoll1[i].GetObject(OpenMode.ForWrite);
  46. if ((Math.Round(pll.Elevation, 4, MidpointRounding.AwayFromZero) != Math.Truncate((Math.Round(pll.Elevation, 4, MidpointRounding.AwayFromZero)))))
  47. {
  48. LayerControl layerscontrol = new LayerControl();
  49. string layname = "已修改";
  50. if (layerscontrol.haslayername(layname) == false)
  51. {
  52. colorgb col = new colorgb(255, 0, 0);
  53. layerscontrol.creatlayer(layname, col);
  54. }
  55. pll.Elevation = Math.Round(pll.Elevation, 0, MidpointRounding.AwayFromZero);
  56. pll.Layer = "已修改";
  57. elelines++;
  58. }
  59. trans.Commit();
  60. }
  61. doclock.Dispose();
  62. }
  63. ed.WriteMessage("\n" + "已修改" + elelines.ToString() + "条高程非整数等高线");
  64. }
  65. }
  66. }
  67. }