Sweep 2 Rails fails in RhinoCommon code

Our code for a RhinoCommon plugin command does not give the desired sweep 2 rails behavior in Rhino 6 (Version 6 SR26 (6.26.20126.12201, 5/5/2020).

Errant sweep using RhinoCommon:


Correct sweep using GUI (manual rail/shape selection):

Code:

        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Curve curve1 = null;
            Curve curve2 = null;
            Curve line1 = null;

            var curveObjs = doc.Objects.GetObjectList(Rhino.DocObjects.ObjectType.Curve);
            foreach (Rhino.DocObjects.RhinoObject crvObj in curveObjs)
            {
                Rhino.DocObjects.ObjRef objref = new Rhino.DocObjects.ObjRef(crvObj.Id);
                Curve crv = objref.Curve();
                switch (crvObj.Attributes.Name)
                {
                    case "trimCL":
                        curve1 = crv;
                        break;
                    case "intCrv":
                        curve2 = crv;
                        break;
                    case "line1":
                        line1 = crv;
                        break;
                }
            }

            double tolerance = doc.ModelAbsoluteTolerance;

            if (curve1 !=null && curve2 != null && line1 != null)
            {
                Brep[] botmSweep = Brep.CreateFromSweep(curve1, curve2, line1, false, tolerance);

                doc.Objects.AddBrep(botmSweep[0]);
            }

            return Result.Success;
        }

We’ve also tried the CreateFromSweep overrides and the SweepTwoRail class. Any additional suggestions would be appreciated.

Hi @jmmorgan,

Can you post your input curve?

Thanks,

– Dale

Input file is attached. Thanks.
SweepInput_RhinoCommon.3dm (22.2 KB)

Hi @jmmorgan,

I’ve logged the issue so a developer can look into this.

https://mcneel.myjetbrains.com/youtrack/issue/RH-58649

– Dale

Hi @jmmorgan,

Brep.CreateFromSweep does not work if there’s only one shape and it’s at the end of the rails. The Sweep2 command uses the same underlying function as Brep.CreateFromSweep, but it figures out a bunch of stuff about the rail orientation first. It’s pretty easy in this case, just calculate the closest points from the start and end of each rail to the shape curve. If the end point is closer than the start point, flip the curve direction.

– Dale

That works. Thank you.