为啥region生成的边界缺少一段
本帖最后由 brainstorm 于 2021-6-16 09:10 编辑region生成的边界缺少一段
public void RegionSubstr()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
//var ent1 = ed.GetEntity("\nSelect Curve");
//建立选择集过滤
TypedValueList tv = new TypedValueList();
tv.Add(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 as Region;
var region2 = Region.CreateFromCurves(new DBObjectCollection { entity2 }) 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;
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();
}
}
图形最大边界 能识别样条曲线 多线段 圆弧 直线 块 并闭合选取状态 可以设置容差 估计很难实现吧?
页:
[1]