How to section a model in C# code

I’m trying to create a transverse section through a (polysurface) boat hull such that the section curve begins at one edge of the hull and traverses all the surfaces (Brep faces) in a clockwise direction (when viewed looking toward positive X) and ends at the opposite edge.

I’ve tried Brep.CreateContourCurves(), but points from some of the interior face edges are ignored. Perhaps there’s a method that includes all edges???

More recently, I’ve been trying to break each face down to a surface and create a curve on that surface using Surface.InterpolatedCurveOnSurface(), but those curves always come up null. I suspect my inputs to the method are not adequate, specifically the first parameter (IEnumerable points). I’ve been the two points that define a line across the hull at the location of the desired section, but that doesn’t work.

Is there a better method or more proper inputs to either method I’ve detailed?

can you share a .3dm file please that shows your intend ?

You should use

Rhino.Geometry.Intersect.Intersection(Brep, Plane, … )

Riccardo - Terrific!!! I will explore that when i get home.

I’m not sure how to do that

just drag and drop a .3dm file into the post-edit window. (File size is limited to 10mb I think)

To “simulate” Intersection(Brep, Plane) as mentioned by Riccardo use
first set is your hull
second set: type IP (inifity Plane) and set the cutting-Plane accordingly.

hull-Plane Intersection.3dm (284.6 KB)

Here’s the model with two resulting curves. One, magenta, is the result of my attempt at Riccardo’s response. It misses three of the six edges in creating the section.

The other, green, is the result of your suggested simulation and is absolutely perfect.

Here is the code, if that helps.

using Rhino;
using Rhino.Commands;
using Rhino.DocObjects;
using Rhino.Geometry;
using Rhino.Input;
using System.Linq;

namespace BrepEdgesIntersections
    public class TestSimplifiedCode : Command
        public TestSimplifiedCode()
            Instance = this;

        ///<summary>The only instance of the MyCommand command.</summary>
        public static TestSimplifiedCode Instance { get; private set; }

        public override string EnglishName => "TestSimplifiedCode";

        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
            var filter = ObjectType.Surface | ObjectType.PolysrfFilter;
            ObjRef obj_ref;
            var rc = RhinoGet.GetOneObject("Select geometry", false, filter, out obj_ref);
            if (rc != Result.Success) return rc;
            var brep = obj_ref.Brep();
            var view = doc.Views.ActiveView;
            var plane = view.ActiveViewport.ConstructionPlane();
            var bbox = brep.GetBoundingBox(plane);

            //The location of one section for this example only
            double dblStaLoc = (bbox.Max.X + bbox.Min.X) / 2;

            int intFaces = brep.Faces.Count;
            BrepFace[] faces = new BrepFace[intFaces];

            Point3d ptBase = new Point3d(dblStaLoc, 0, 0);
            Point3d ptEnd = new Point3d(dblStaLoc, 1, 0);
            Point3d pt3 = new Point3d(dblStaLoc, 0, 1);
            Point3d[] plnpts = new Point3d[2];
            plnpts[0] = ptBase; plnpts[1] = ptEnd;
            Plane pln= new Plane(ptBase, ptEnd, pt3);
            Point3d[] points = new Point3d[intFaces * 30];
            Point3d[] pts = new Point3d[30];
            Polyline pl = new Polyline();

            Curve[] crvs = new Curve[100];
                    Rhino.Geometry.Intersect.Intersection.BrepPlane(brep, pln, 0.001, out crvs, out points);
                    if (crvs != null && crvs.Count() > 0)
                        foreach(Curve crv in crvs)
                            crv.DivideByCount(10, true, out pts);
                            foreach (Point3d pt in pts)
                            }//foreach (Point3d pt in pts)
                        }//foreach(Curve crv in crvs)
                    }//if (crvs != null && crvs.Count() > 0)
            return Result.Success;
        }// protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    }//public class TestSimplifiedCode : Command
}//namespace BrepEdgesIntersections

to debug the result of the intersection - add the resulting Curves to the document as they are !
something like this

foreach(Curve crv in crvs)
                           // later add the polyline conversion
                        }//foreach(Curve crv in crvs)

also note, that the curves are of the intersection are in random order - maybe related to the Index of the corresponding edge-Face.