Sweep Two Rail, Maintain Height

Hi, I am trying to do a Sweep Two Rail in Grasshopper with the Maintain Height property. I’ve tried using the Sweep2 component, however the Maintain Height (H) property is not working. Any ideas on why this might be? I tried to script it, but I can’t find a function with the Maintain Height option.

SweepTwoRailPython_AHD.gh (12.7 KB)

Does Maintain Height actually work with your input geometry with the normal Rhino command? Maybe the geometry doesn’t allow it.

As far as scripting goes, the maintain height option is not available via rhinoscriptsyntax. You will have to use the SweepTwoRail class directly from RhinoCommon.

–Mitch

Yes, it works perfectly within Rhino, but not in Grasshopper (I’m attaching an image to see the difference). Meanwhile, I’ll take a look at the RhinoCommon link you just sent. Thanks Helvetosaur!

@fernandomaytorena,

it is a bug in the Sweep2 component. Double click in your grasshopper canvas, enter #Sweep2 and choose the old Sweep2 component.

c.

Wow, I didn’t now you could pick old components, thanks @clement. However, I did what you said and the old Sweep2 component does not work, it outputs an empty BRep parameter.

Old SweepTwoRail Failed.gh (23.4 KB)

Check if below example files work. I get a result here and maintain height does something…

Sweep2Rail_Old.3dm (66.0 KB)

Sweep2Rail_Old.gh (9.5 KB)

To check your file i need to see your section curves and rails involved as a rhino file. Your last example seems to work using my curves. What gh version you have ?

c.

@fernandomaytorena,

i see now: the old component does not like closed rails, but maintain height works. The new component accepts the closed rails, but maintain height does not work. :confused:

c.

Hahaha just what I was about to say. The Rhino and GH files you sent worked perfectly on my computer also. Then I tried to input my own Rhino file’s geometry, and again the same problem (new component: does not maintain height; old component: does not create BRep). I guess I’ll keep searching through the scripting way. Thanks though @clement

@fernandomaytorena,

i think scripting will give you the similar problems, since python uses the same RhinoCommon based code from the sdk as the new gh Sweep2 component uses. To check this, paste below script into the python editor (_EditPythonScript):

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def Sweep2Rails(r1, r2, s, maintain_height=False, closed=False):
    sweep = Rhino.Geometry.SweepTwoRail()
    sweep.AngleToleranceRadians = scriptcontext.doc.ModelAngleToleranceRadians
    sweep.SweepTolerance = scriptcontext.doc.ModelAbsoluteTolerance
    sweep.MaintainHeight = maintain_height
    sweep.ClosedSweep = closed
    return sweep.PerformSweep(r1, r2, s)
    
def DoSomething():
    id_r1 = rs.GetObject("Select first rail", 4, True, False)
    if not id_r1: return
    id_r2 = rs.GetObject("Select second rail", 4, False, False)
    if not id_r2: return
    id_s = rs.GetObjects("Select cross section curves", 4, False, False, False)
    if not id_s: return
    
    r1 = rs.coercecurve(id_r1, -1, True)
    r2 = rs.coercecurve(id_r2, -1, True)
    s = [rs.coercecurve(id, -1, True) for id in id_s]
    
    rc = Sweep2Rails(r1, r2, s, maintain_height=True, closed=False)
    if rc: 
        breps = [scriptcontext.doc.Objects.AddBrep(brep) for brep in rc]
        scriptcontext.doc.Views.Redraw()
        return breps
    
DoSomething()

At the moment, the function call (line 25 in the script above) creates the sweep2 with

Sweep2Rails(r1, r2, s, maintain_height=True, closed=False)

If you try the script using 2 closed rails, it will create a brep and maintain height works. If you set closed=True, there often is no output. Try the example file below with the script.

@dale, i think this is a bug in RhinoCommon which affects python and gh.

Sweep2Rail.3dm (72.3 KB)

c.

@fernandomaytorena,

one important thing: if it fails, make sure that the rail curves have same directions and that the first section is positioned at the start of the rail curves, all other sections should be in order. The python version does not autosort the curves. Apart from this i was able to make a closed sweep2 with 4 sections and maintain height enabled. (in the Rhino wip with built in GH + Python component.)

c,

@clement

Yes, I do have have both rails with the same direction, the first section positioned at the start of the rail curves and all other sections in order. I used the same script you used, but I get a syntax error, I think it has to do with my Python version or something like that. I’m attaching an image, the Rhino file, and the Grasshopper definition.

Sweep2Rail_Old Rhino.3dm (235.8 KB)
sweep2.gh (11.6 KB)

@fernandomaytorena,

yes, in the last example code i was trying only with a single section, where it also failed with closed rails. To make it work with single or multiple sections i just changed:

s = rs.coercecurve(S)

to:

s = [rs.coercecurve(id) for id in S]

Note, I´ve used a single input “Sections” in my definition. But i guess this does not really help. The python component works for open rails, but not always for closed rails, like the ones you`re trying. Regardless of the maintain height setting, it just creates nothing. In the picture below i´ve added an option toggle to control “Closed”. Once i set Closed=False, i get no result.

The error seems to apply for all 3 sweep methods i´ve tried:

sweep.PerformSweep()
sweep.PerformSweepRefit(r1, r2, s, 0.001)
sweep.PerformSweepRebuild(r1, r2, s, 100)

I´ve found that the python version of sweep2 sometimes fails on simplest cases too, eg. try a sweep2 using two rectangles as rails and a single linear section connecting the rectangles at their start points…

c.

@clement bottom line, I won’t be able to do the Sweep2 I need within Grasshopper?

@fernandomaytorena, there are still the C#.NET and VB.NET components to try :smile:

maybe, as a quick workaround, you should not make the Sweep2 in one surface. But you could make a partial sweep using section 1,2,3 (first surface), then mirror over X-Axis to get the second surface.

baked result: Fernando.3dm (1.7 MB)

c.

Yes, I think I’ll end up doing the workaround haha thanks for all your help @clement