1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- using GrxCAD.ApplicationServices;
- using GrxCAD.DatabaseServices;
- using GrxCAD.EditorInput;
- using GrxCAD.Geometry;
-
- namespace HCTools
- {
- class CheckContourLine
- {
- public static int gap;
- public static string jqx;
- public static string sqx;
-
- public void Valuecheck()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- string LayerName = jqx + "," +sqx;
- ObjectId[] ids = BasicFunction.getHeight(LayerName);//存放获取的等高线id
-
-
- //如果没有等高线则返回
- if (ids == null)
- return;
-
- //检查是否有错误曲线图层,没有则创建
- LayerControl layerscontrol = new LayerControl();
- string layname = "等高线有误";
- if (!layerscontrol.haslayername(layname))
- {
- colorgb col = new colorgb(255, 0, 225);
- layerscontrol.creatlayer(layname, col);
- layerscontrol.movelayertofront(layname);
- }
- else
- layerscontrol.movelayertofront(layname);
-
- int j = 0;
- int num = 0;
- for (int i = 0; i < ids.Length; i++)
- {
- Polyline pll = BasicFunction.GetDBObject(ids[i]) as Polyline;
- if (pll.Elevation <= 0)
- {
- ChangeLayer(pll.Id, layname);
- j++;
- }
- else
- {
- if (int.TryParse(Math.Round(pll.Elevation, 3, MidpointRounding.AwayFromZero).ToString(), out num))
- {
- if (Math.Round(pll.Elevation,3, MidpointRounding.AwayFromZero) % gap == 0)
- {
- continue;
- }
- else
- {
- ChangeLayer(pll.Id, layname);
- j++;
- }
- }
- else
- {
- ChangeLayer(pll.Id, layname);
- j++;
- }
- }
- }
- Editor ed = doc.Editor; ed.WriteMessage("共有" + j + "处错误");
- }
-
-
- private void ChangeLayer(ObjectId c1Id, string lyname)
- {
- Database db = HostApplicationServices.WorkingDatabase;
- 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);
- Entity ent1 = (Entity)c1Id.GetObject(OpenMode.ForWrite);
- ent1.Layer = lyname;
- trans.Commit();
- }
- doclock.Dispose();
- }
- }
- }
-
|