123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- using GrxCAD.ApplicationServices;
- using GrxCAD.DatabaseServices;
- using GrxCAD.EditorInput;
- using GrxCAD.Geometry;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace HCTools
- {
- class DgxAnnck
- {
- public static string ptlayer;
- public static string tklayer;
- public static double density;
- public static int flag;
-
- public void check()
- {
- ObjectId[] ids = TKget();
-
- Database db = HostApplicationServices.WorkingDatabase;
- DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
-
- TypedValue[] typedvalue = new TypedValue[1];
- typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, ptlayer), 0);
- SelectionFilter selectionfilter = new SelectionFilter(typedvalue);
-
- for (int i = 0; i < ids.Length; i++)
- {
- Entity current_entity = BasicFunction.GetDBObject(ids[i]);
- ZoomToExtent(current_entity.GeometricExtents);
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- Polyline pll = (Polyline)trans.GetObject(ids[i], OpenMode.ForWrite);
- Point3dCollection ptcoll = new Point3dCollection();
- for (int j = 0; j < pll.NumberOfVertices; j++)
- {
- ptcoll.Add(pll.GetPoint3dAt(j));
- }
- PromptSelectionResult psr = editor.SelectCrossingPolygon(ptcoll, selectionfilter);
-
- if (psr.Status == PromptStatus.OK)
- {
- SelectionSet selectionset = psr.Value;
- int ptnums = selectionset.Count;
- double den = ptnums / pll.Area;
- if (den < density && flag == 1)
- {
- LayerControl layerscontrol = new LayerControl();
- string layname = "小于密度";
- if (!layerscontrol.haslayername(layname))
- {
- colorgb col = new colorgb(0, 0, 255);
- layerscontrol.creatlayer(layname, col);
- pll.Layer = "小于密度";
- }
- else
- pll.Layer = "小于密度";
- }
- else if (den > density && flag == 2)
- {
- LayerControl layerscontrol = new LayerControl();
- string layname = "大于密度";
- if (!layerscontrol.haslayername(layname))
- {
- colorgb col = new colorgb(255, 0, 0);
- layerscontrol.creatlayer(layname, col);
- pll.Layer = "大于密度";
- }
- else
- pll.Layer = "大于密度";
- }
- else if (flag == 3)
- {
- if (den < density || den > density)
- {
- LayerControl layerscontrol = new LayerControl();
- string layname = "不等于密度";
- if (!layerscontrol.haslayername(layname))
- {
- colorgb col = new colorgb(255, 255, 0);
- layerscontrol.creatlayer(layname, col);
- pll.Layer = "不等于密度";
- }
- else
- pll.Layer = "不等于密度";
- }
- }
- }
- trans.Commit();
- }
- }
- doclock.Dispose();
- }
-
- private static ObjectId[] TKget()
- {
- Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- TypedValue[] typedvalue = new TypedValue[1];
- typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, tklayer), 0);
-
- SelectionFilter selectionfilter = new SelectionFilter(typedvalue);
- PromptSelectionResult psr = editor.SelectAll(selectionfilter);
- SelectionSet selectionset = psr.Value;
- ObjectId[] obj = new ObjectId[selectionset.Count];
-
- if (psr.Status == PromptStatus.OK)
- {
- obj = selectionset.GetObjectIds();
- }
- return obj;
- }
-
- public static void ZoomToExtent(Extents3d extent)
- {
- try
- {
- Point3d pMin = extent.MinPoint;
- Point3d pMax = extent.MaxPoint;
- //获取当前文档及数据库
- Document acDoc = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Database acCurDb = acDoc.Database;
-
- // 启动事务
- using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
- {
- using (ViewTableRecord acView = acDoc.Editor.GetCurrentView())
- {
- //设置视图的高
- acView.Height = Math.Abs(pMin.Y - pMax.Y);
- //设置视图的宽
- acView.Width = Math.Abs(pMin.X - pMax.X);
- // 设置视图中心
- acView.CenterPoint = new Point2d((pMin.X + pMax.X) / 2, (pMin.Y + pMax.Y) / 2);
- // 更新当前视图
- acDoc.Editor.SetCurrentView(acView);
- }
- // 提交更改
- acTrans.Commit();
- }
- }
- catch (Exception)
- {
-
- throw;
- }
- }
- }
- }
|