SweepTwoRail not working while manual Sweep2 command works

Hi everybody,

I am trying to implement the use of a Sweep2 operation in a plugin that we are writing. When I do the operation while manually selecting the curves in Rhino, the operation gives a nice result:

In our plugin I first tried to use the Brep.CreateFromSweep() method, but that gave very unsatisfying results:

When using the SweepTwoRail class as is mentioned in the Brep.CreateFromSweep() documentation, I always get an empty Brep back.

Does anybody have any idea what I am doing wrong?

Here is the code that I use to test this functionality and the 3dm file with the actual curves :
allcurves.3dm (42.5 KB)

protected override Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
    {
        // Select Rail 1
        GetObject go = new GetObject();
        go.SetCommandPrompt("Select the first curve");
        const ObjectType curveFilter = ObjectType.Curve;
        go.GeometryFilter = curveFilter;
        go.DisablePreSelect();
        go.SubObjectSelect = false;

        Curve rail1;
        while (true)
        {
            GetResult res = go.Get();
            if (res == GetResult.Nothing)
            {
                return Result.Failure;
            }
            else
            {
                rail1 = go.Object(0).Geometry() as Curve;
                break;
            }
        }


        // Select Rail 2
        go = new GetObject();
        go.SetCommandPrompt("Select the second curve");
        go.GeometryFilter = curveFilter;
        go.DisablePreSelect();
        go.SubObjectSelect = false;

        Curve rail2;
        while (true)
        {
            GetResult res = go.Get();
            if (res == GetResult.Nothing)
            {
                return Result.Failure;
            }
            else
            {
                rail2 = go.Object(0).Geometry() as Curve;
                break;
            }
        }


        // Select Guides
        go = new GetObject();
        go.SetCommandPrompt("Select the guiding curves");
        go.GeometryFilter = curveFilter;
        go.DisablePreSelect();
        go.SubObjectSelect = false;

        List<Curve> guidingCurves = new List<Curve>();
        while (true)
        {
            GetResult res = go.Get();
            if (res == GetResult.Nothing || res == GetResult.Cancel)
            {
                break;
            }
            else
            {
                foreach (ObjRef r in go.Objects())
                {
                    guidingCurves.Add(r.Geometry() as Curve);
                }
            }
        }

        RhinoApp.WriteLine("Selected {0} guide curves",guidingCurves.Count());


        // Do the Sweep with Brep.CreateFromSweep -> a result, but not helpful
        Brep[] simple = Brep.CreateFromSweep(rail1, rail2, guidingCurves, true, doc.ModelAbsoluteTolerance);
        foreach (Brep bb in simple)
        {
            doc.Objects.Add(bb);
        }


        // Do the Sweep2 with Sweep two rail -> no result
        SweepTwoRail t = new SweepTwoRail();
        t.ClosedSweep = true;
        t.MaintainHeight = false;
        t.AngleToleranceRadians = doc.ModelAngleToleranceRadians;
        t.SweepTolerance = doc.ModelAbsoluteTolerance;
        // This sweepSkirt is always empty
        Brep[] sweepSkirt = t.PerformSweep(rail1, rail2, guidingCurves);
        foreach (Brep bb in sweepSkirt)
        {
            doc.Objects.Add(bb);
        }

        // end
        doc.Views.Redraw();            
        return Result.Success;
    }

@lowell, can you provide any wisdom here?

It appears that there was an issue in Brep.CreateFromSweep dealing with the orientation of the rails curves. This has been fixed in the WIP and will be available next week for testing. Unfortunately it doesn’t look like there will be another Rhino 5 service release.

Going forward, the SweepTwoRail class is obsolete and will be removed for V6. Thus, you will want to continue to use the static function on Rhino.Geometry.Brep.

Thanks for the reply.

Is there any workaround that I could apply, or any alternative method that I could use that provides more or less similar results?

Some pre-processing on the curve orientation, perhaps? Or a ‘deeper’ algorithm that creates rectangular Brep patches for each patch bounded by 2 construction curves?

I know this is cheezy, but you can always script the Sweep2 command. See the attached for an example.

TestScriptedSweep2.zip (1.3 KB)

Cheezy or not, it works! Thank you for the help.
I did not know that everything could be scripted like that, even commands that have a popup window.