马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 brainstorm 于 2021-6-16 14:23 编辑
- //为什么regionregion生成的边界会缺少一段
复制代码
- [CommandMethod("testregion")]
- public void RegionSubstr()
- {
- var doc = Application.DocumentManager.MdiActiveDocument;
- var db = doc.Database;
- var ed = doc.Editor;
- //var ent1 = ed.GetEntity("\nSelect Curve");
- //建立选择集过滤
- ResultBuffer tv = new ResultBuffer(); tv.Add(new TypedValue(0, "*line"));
- SelectionFilter fil = new SelectionFilter(tv);
- PromptSelectionOptions pso = new PromptSelectionOptions();
- pso.MessageForAdding = "\n select curves:";
- PromptSelectionResult psr = ed.GetSelection(pso, fil);
- if (psr.Status != PromptStatus.OK)
- {
- ed.WriteMessage("\n selection is null!");
- return;
- }
- PromptEntityResult ent = ed.GetEntity("\nselect curve to be substracted:");
- using (var tr = db.TransactionManager.StartTransaction())
- {
- BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- ObjectId oId = ent.ObjectId;
- Entity entity2 = tr.GetObject(oId, OpenMode.ForWrite) as Entity;
- var curveSegments = new DBObjectCollection();
- foreach (var id in psr.Value.GetObjectIds())
- {
- curveSegments.Add(tr.GetObject(id, OpenMode.ForRead) as Entity);
- }
- var regions = Region.CreateFromCurves(curveSegments);
- var region1 = regions[0] as Region;
- var region2 = Region.CreateFromCurves(new DBObjectCollection { entity2 })[0] as Region;
- if (region1 != null)
- {
- region1.BooleanOperation(BooleanOperationType.BoolSubtract, region2);
- Brep brep = new Brep(region1);
- BrepFaceCollection faces = brep.Faces;
- BoundaryLoop boundaryLoop = faces.First().Loops.First();
- Edge[] boundaryEdges = boundaryLoop.Edges.ToArray();
- Curve3d[] cv3 = new Curve3d[boundaryEdges.Count()];
- for (int i = 0; i < boundaryEdges.Count(); i++)
- {
- cv3 = (boundaryEdges.Curve as ExternalCurve3d).NativeCurve;
- }
- CompositeCurve3d cc3 = new CompositeCurve3d(cv3);
- var newCv1 = Curve.CreateFromGeCurve(cc3);
- newCv1.ColorIndex = 1;
- btr.AppendEntity(newCv1);
- tr.AddNewlyCreatedDBObject(newCv1, true);
- }
- tr.Commit();
- }
- }
|