1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using GrxCAD.DatabaseServices;
- using GrxCAD.Geometry;
- using GrxCAD.ApplicationServices;
- using GrxCAD.EditorInput;
- using System.Windows.Forms;
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace HCTools
- {
- class EleRound
- {
- public static string jqx;
- public static string sqx;
- public void eleround()
- {
- Database db = HostApplicationServices.WorkingDatabase;
- Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
-
- string lyrname = jqx + "," + sqx;
- //选择要取整等高线
- TypedValue[] value = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,lyrname),
- new TypedValue((int)DxfCode.Start,"LWPOLYLINE")
- };//设置筛选条件
- SelectionFilter filter = new SelectionFilter(value);//选择区域中全部对象
- //PromptSelectionResult psr = ed.SelectAll(filter);// 要求在图形区域中手动选择对象
- PromptSelectionResult psr = ed.GetSelection(filter);
-
- if (psr.Status == PromptStatus.OK)
- {
- int elelines = 0;
- SelectionSet ss = psr.Value;
- if (ss == null)
- return;
- ObjectIdCollection idcoll1 = new ObjectIdCollection(ss.GetObjectIds());
- for (int i = 0; i < idcoll1.Count; i++)
- {
- DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- Polyline pll = (Polyline)idcoll1[i].GetObject(OpenMode.ForWrite);
- if ((Math.Round(pll.Elevation, 4, MidpointRounding.AwayFromZero) != Math.Truncate((Math.Round(pll.Elevation, 4, MidpointRounding.AwayFromZero)))))
- {
- LayerControl layerscontrol = new LayerControl();
- string layname = "已修改";
- if (layerscontrol.haslayername(layname) == false)
- {
- colorgb col = new colorgb(255, 0, 0);
- layerscontrol.creatlayer(layname, col);
- }
- pll.Elevation = Math.Round(pll.Elevation, 0, MidpointRounding.AwayFromZero);
- pll.Layer = "已修改";
- elelines++;
- }
- trans.Commit();
- }
- doclock.Dispose();
- }
- ed.WriteMessage("\n" + "已修改" + elelines.ToString() + "条高程非整数等高线");
- }
- }
- }
- }
|