Code Red > .NET

why segment of curves created by region boundary is missing

(1/1)

brainstormcn:

--- Code - C#: ---[CommandMethod("testregion")]        public void RegionSubstr()        {            var doc = Application.DocumentManager.MdiActiveDocument;            var db = doc.Database;            var ed = doc.Editor;             //var ent1 = ed.GetEntity("\nSelect Curve");            //&#24314;&#31435;&#36873;&#25321;&#38598;&#36807;&#28388;            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[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[i] = (boundaryEdges[i].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();            }        } 

Navigation

[0] Message Index

Go to full version