明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 549|回复: 1

[图元] 为啥region生成的边界缺少一段

[复制链接]
发表于 2021-6-16 08:58 | 显示全部楼层 |阅读模式
本帖最后由 brainstorm 于 2021-6-16 09:10 编辑

  1. region生成的边界缺少一段


  1. [CommandMethod("testregion")]
  2.         public void RegionSubstr()
  3.         {
  4.             var doc = Application.DocumentManager.MdiActiveDocument;
  5.             var db = doc.Database;
  6.             var ed = doc.Editor;

  7.             //var ent1 = ed.GetEntity("\nSelect Curve");
  8.             //建立选择集过滤
  9.             TypedValueList tv = new TypedValueList();
  10.             tv.Add(0, "*line");
  11.             SelectionFilter fil = new SelectionFilter(tv);
  12.             PromptSelectionOptions pso = new PromptSelectionOptions();
  13.             pso.MessageForAdding = "\n select curves:";
  14.             PromptSelectionResult psr = ed.GetSelection(pso, fil);

  15.             if (psr.Status != PromptStatus.OK)
  16.             {
  17.                 ed.WriteMessage("\n selection is null!");
  18.                 return;
  19.             }
  20.             PromptEntityResult ent = ed.GetEntity("\nselect curve to be substracted:");

  21.             using (var tr = db.TransactionManager.StartTransaction())
  22.             {
  23.                 BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
  24.                 ObjectId oId = ent.ObjectId;
  25.                 Entity entity2 = tr.GetObject(oId, OpenMode.ForWrite) as Entity;
  26.                 var curveSegments = new DBObjectCollection();
  27.                 foreach (var id in psr.Value.GetObjectIds())
  28.                 {
  29.                     curveSegments.Add(tr.GetObject(id, OpenMode.ForRead) as Entity);
  30.                 }

  31.                 var regions = Region.CreateFromCurves(curveSegments);
  32.                 var region1 = regions[0] as Region;
  33.                 var region2 = Region.CreateFromCurves(new DBObjectCollection { entity2 })[0] as Region;

  34.                 if (region1 != null)
  35.                 {
  36.                     region1.BooleanOperation(BooleanOperationType.BoolSubtract, region2);

  37.                     Brep brep = new Brep(region1);
  38.                     BrepFaceCollection faces = brep.Faces;
  39.                     BoundaryLoop boundaryLoop = faces.First().Loops.First();
  40.                     Edge[] boundaryEdges = boundaryLoop.Edges.ToArray();

  41.                     Curve3d[] cv3 = new Curve3d[boundaryEdges.Count()];
  42.                     for (int i = 0; i < boundaryEdges.Count(); i++)
  43.                     {
  44.                         cv3[i] = (boundaryEdges[i].Curve as ExternalCurve3d).NativeCurve;
  45.                     }
  46.                     CompositeCurve3d cc3 = new CompositeCurve3d(cv3);
  47.                     var newCv1 = Curve.CreateFromGeCurve(cc3);
  48.                     newCv1.ColorIndex = 1;
  49.                     btr.AppendEntity(newCv1);
  50.                     tr.AddNewlyCreatedDBObject(newCv1, true);
  51.                 }
  52.                 tr.Commit();
  53.             }
  54.         }


发表于 2023-2-24 11:19 | 显示全部楼层
图形最大边界 能识别样条曲线 多线段 圆弧 直线 块 并闭合选取状态 可以设置容差   估计很难实现吧?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-28 08:48 , Processed in 0.313254 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表