CAD二次开发获取当前视角范围内对象

复制代码
 1 private List<Curve> GetCurveFromView() {
 2             List<Curve> curves = new List<Curve>();
 3             ViewTableRecord viewTableRecord = ed.GetCurrentView();
 4             double w = viewTableRecord.Width;
 5             double h = viewTableRecord.Height;
 6             Point2d point = viewTableRecord.CenterPoint;
 7             Point3d P1 = new Point3d(point.X - w / 2, point.Y - h / 2, 0);
 8             Point3d P2 = new Point3d(point.X + w / 2, point.Y + h / 2, 0);
 9             PromptSelectionResult promptSelectionResult = ed.SelectCrossingWindow(P1, P2);
10             if (promptSelectionResult.Status == PromptStatus.OK)
11             {
12                 ObjectId[] objectIds = promptSelectionResult.Value.GetObjectIds();
13                 using (Transaction trans = doc.TransactionManager.StartTransaction())
14                 {
15                     foreach (ObjectId objectId in objectIds)
16                     {
17                         Curve curve = trans.GetObject(objectId, OpenMode.ForRead) as Curve;
18                         if (curve != null) {
19                             curves.Add(curve);
20                         }
21                     }
22                 }
23             }
24 
25             return curves;
26         }
复制代码

 

posted @   百年一梦  阅读(604)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 提示词工程——AI应用必不可少的技术
· 地球OL攻略 —— 某应届生求职总结
· 字符编码:从基础到乱码解决
· SpringCloud带你走进微服务的世界
点击右上角即可分享
微信分享提示