当前位置: 首页 > news >正文

030集——分组法——C# CAD二次开发

重叠的图行进行分组,效果如下:

Y轴投影重叠(横向移动冲突)可以分组:

 纵向冲突也可以分组:

也可根据颜色不同分组:

部分代码如下,完整代码见文章下方名片 

 public class Class1{[CommandMethod("xx")]public void XX(){var entities = Z.db.SelectEntities<Entity>();var bigList = Z.GroupEntities(entities);foreach (var smallList in bigList){//Extents3d extents = new Extents3d();//entity.ForEach(x => extents.AddExtents(x.GeometricExtents));//x=>extents.Z.GetboxsAndDraw(smallList);}}
  public static List<T> SelectEntities<T>(this Database db ) where T : Entity{List<T> result = new List<T>();Editor editor = Application.DocumentManager.MdiActiveDocument.Editor;var pso = new PromptSelectionOptions();pso.MessageForAdding = "\n请选择:";PromptSelectionResult psr = editor.GetSelection(pso);if (psr.Status == PromptStatus.OK){ObjectId[] objectids = psr.Value.GetObjectIds();Database database = HostApplicationServices.WorkingDatabase;using (Transaction tran = database.TransactionManager.StartTransaction()){foreach (var item in objectids){Entity entity = item.GetObject(OpenMode.ForRead) as Entity;if (entity is T){result.Add(entity as T);}}}}return result;}
      class Friend{public int Id { set; get; }public List<Friend> Friends { get; set; }public Friend(int id){Id = id;Friends = new List<Friend>();}}
  public static bool IsOverlapping(Entity entity1, Entity entity2){Point3dCollection pos = new Point3dCollection();entity1.IntersectWith(entity2, Intersect.OnBothOperands, pos, IntPtr.Zero, IntPtr.Zero);return pos.Count > 0;}
     public static ObjectId GetboxsAndDraw(List<Entity> entities){List<double> lis = new List<double>();if (entities.Count == 0){return ObjectId.Null;}double minx = entities.Min(x => x.Bounds.Value.MinPoint.X);double miny = entities.Min(x => x.Bounds.Value.MinPoint.Y);double maxx = entities.Max(x => x.Bounds.Value.MaxPoint.X);double maxy = entities.Max(x => x.Bounds.Value.MaxPoint.Y);lis.Add(minx);lis.Add(miny);lis.Add(maxx);lis.Add(maxy);Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline();pl.AddVertexAt(0, new Point2d(minx ,miny),0,0,0);pl.AddVertexAt(0, new Point2d(maxx, miny), 0, 0, 0);pl.AddVertexAt(0, new Point2d(maxx, maxy), 0, 0, 0);pl.AddVertexAt(0, new Point2d(minx, maxy), 0, 0, 0);pl.Closed = true;pl.ColorIndex = 1;db.AddEntityToModeSpace(pl);return pl.ObjectId;}

   public static List<List<Entity>> GroupEntities(List<Entity> entities){List<List<Entity>> result = new List<List<Entity>>();List<Friend> friends = new List<Friend>();for (int i = 0; i < entities.Count; i++){Friend friend = new Friend(i);friends.Add(friend);}for (int i = 0; i < entities.Count - 1; i++){for (int j = 0; j < entities.Count; j++){if (Z.IsOverlapping(entities[i], entities[j])){friends[i].Friends.Add(friends[j]);friends[j].Friends.Add(friends[i]);}}}
****部分代码return result;}


http://www.mrgr.cn/news/67433.html

相关文章:

  • layui 实现 城市联动
  • 搭建企业私有云 只需一台设备 融合计算、存储与K8s
  • nginx配置代理地址
  • stm32仿真教程新建Proteus工程添加STM32芯片
  • python实现RSA算法
  • 模块化开发 webpack
  • 云服务器上的网站取消301重定向功能
  • qt QCompleter详解
  • 【CAN总线协议】CAN和CANFD的区别、CAN FD帧结构解析
  • 制造业仓储信息化总体规划方案
  • 康坦电商发布2024年度战略:立足中国,开拓全球市场
  • Redux的简介及其在React中的应用
  • 想要搭建陪玩系统小程序,这几点不容忽视,陪玩系统源码框架
  • 在Java中抽象类和接口的区别是什么?
  • PySpark本地开发环境搭建
  • 华为机试HJ27 查找兄弟单词
  • 用接地气的例子趣谈 WWDC 24 全新的 Swift Testing 入门(三)
  • FQDN(Fully Qualified Domain Name,完全限定域名)是指能够唯一标识互联网上一台主机的域名
  • (61)使用LMS算法估计线性预测器并计算估计误差的MATLAB仿真
  • .NET 白名单文件通过反序列化执行系统命令
  • PN结特性及反向饱和电流与反向漏电流详解
  • 【机器学习】聚类算法分类与探讨
  • 1.6K+ Star!Ichigo:一个开源的实时语音AI项目
  • 边缘计算的基本概念与实践
  • 探讨Mysql和Redis的数据实时同步方案
  • Java之随机点名器(4)