035集——BOUNDARY获取图形外轮廓(CAD—C#二次开发入门)

通过使用类似命令行输入boundary的方法获取图形外轮廓,使用函数如下:

var pls = Z.ed.TraceBoundary(new Point3d(box[0] - 100, box[1]-100,0),true);

效果如下:

cs 复制代码
 public void XX()
 {
     Point3d pt = new Point3d(0, 0, 0);
     List<Curve> ents = Z.db.SelectEntities<Curve>();
     //Z.DrawBigBox<Curve>(ents);
     List<double> box = Z.Getbox<Curve>(ents);
     if (ents == null || ents.Count == 0) return;
     Entity temp=  Z.DrawBigBoxAdd(ents);
     List<Entity> plr = new List<Entity>();  //   
     var pls = Z.ed.TraceBoundary(new Point3d(box[0] - 100, box[1]-100,0),true);
     foreach (Entity item in pls)//不能var,否则没bounds属性
     {
         if (item.Bounds.Value.MinPoint.X != box[0]-1000)
         {
             item.Color = Color.FromRgb(255, 0, 0);
             plr.Add(item);
         }
     }
     Z.db.AddEntityToModeSpace(plr.ToArray());
     Z.db.Erase(temp);
 }
cs 复制代码
 public static List<double> Getbox<T>(List<T> entities)where T : Entity
 {
     List<double> lis = new List<double>();
     if (entities.Count == 0)
     {
         return lis;
     }
     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);
     return lis;
 }

  public static Entity DrawBigBoxAdd(List<Curve> entities)
  {//传进来一个list,画list的总包围盒
      List<double> lis = new List<double>();
      if (entities.Count == 0)
      {
          return null;
      }
      double minx = entities.Min(x => x.Bounds.Value.MinPoint.X - 1000);
      double miny = entities.Min(x => x.Bounds.Value.MinPoint.Y - 1000);
      double maxx = entities.Max(x => x.Bounds.Value.MaxPoint.X + 1000);
      double maxy = entities.Max(x => x.Bounds.Value.MaxPoint.Y + 1000);
      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;
  }
相关推荐
宅小海5 分钟前
scala String
大数据·开发语言·scala
qq_327342737 分钟前
Java实现离线身份证号码OCR识别
java·开发语言
锅包肉的九珍8 分钟前
Scala的Array数组
开发语言·后端·scala
心仪悦悦12 分钟前
Scala的Array(2)
开发语言·后端·scala
yqcoder34 分钟前
reactflow 中 useNodesState 模块作用
开发语言·前端·javascript
Heaphaestus,RC36 分钟前
【Unity3D】获取 GameObject 的完整层级结构
unity·c#
baivfhpwxf20231 小时前
C# 5000 转16进制 字节(激光器串口通讯生成指定格式命令)
开发语言·c#
许嵩661 小时前
IC脚本之perl
开发语言·perl
长亭外的少年1 小时前
Kotlin 编译失败问题及解决方案:从守护进程到 Gradle 配置
android·开发语言·kotlin
直裾1 小时前
Scala全文单词统计
开发语言·c#·scala