Is Sweep1 Broken in Rhino.Geometry and Grasshopper?

It works fine with circlular rails, but you can see that for rectangular rails, I get a crazy result.

This is the code:
rectangle sweep problem.py (855 Bytes)

What am I doing wrong?

Update:
It seems broken in Grasshopper, too. You can see it is sweeping the circle but not the rectangle.

sweep1 problem.gh (14.8 KB)

Update2:
Even weirder…it works in GH if I swap the rail and cross-section shape. It’s not giving exactly the result I was expecting, but it is performing the sweep.

Update3:
So, if I swap the rail and shape in the Rhino.Geometry.Brep.CreateFromSweep, it starts working (although I was expecting the sweep to flare outward at the bottom all the way around…which is what happens if you manually perform a sweep1 using the Rhino tools.)

Update4:
Okay, I just realize that when I swap the rail and cross-section, the sweep is skewed because it it is in fact treating the cross-section shape as the rail. So ignore Update3. I still wonder why it won’t sweep the rectangle in Grasshopper, though.

hello,

i read your post from the beginning,
but i still don’t understand what you want to get as a final result from the initial geometries

at least a photo posted only the initial curves and what srf shape you want to have

1 Like

The shape I’m trying to make is this, which I can easily do using the Rhino tools (just sweep the angled line around the rectangle)

But the reason I’m making that shape is that I’m just experimenting with making ETO forms with sliders that can control geometry, but when I went to make the sweep, it didn’t work. And I spent hours trying to figure out what I was doing wrong. But now I think the problem is in the code since it also doesn’t work in grasshopper and since it does work (in both grasshopper and the python code) if I swap the rail and cross-section curves in the inputs.

in fact I still don’t understand how you are proceeding, first you share a Py script that as far as my (even if not much) knowledge I have not really understood the meaning of the sequence of commands with the purpose you want to achieve, then you mentioned both ETO and in the Py code I do not see a shadow that posted a def of GH, so personally I think that you should first clarify well with which tool you want to solve the problem and focus only on that.

anyway the only thing that at this moment I can suggest to you, and that with whatever tool you decide to proceed the steps are these:

you have to use the Sweep2 command
indicate the first large track of the base
then indicate the second small track the one at the top
and finally indicate the “line” of section that closes everything
ps I would advise you to create the section line using the two start/end points of the two tracks (since I imagine they are both closed curves?) being careful that the aforementioned points cited are corresponding.

second tip, with such simple geometries you could also try using the loft command, so you would simplify everything if the result is ok.

Hi @webdunce,

Does this help?

#! python 2

import Rhino
import Rhino.Geometry as rg
import scriptcontext as sc
import math

radius = 3
sweepWidth = 2.5
angle = math.radians(20)

cornerA = rg.Point3d(-radius, radius, 0)
cornerB = rg.Point3d(radius, -radius, 0)
rect = rg.Rectangle3d(rg.Plane.WorldXY, cornerA, cornerB).ToPolyline()
rail = rg.PolylineCurve(rect)

startPnt = rg.Point3d(radius, 0, 0)
endPnt = rg.Point3d(radius+sweepWidth, 0, 0)

line = rg.Line(startPnt, endPnt)
shape = rg.LineCurve(line)

xform = rg.Transform.Rotation(angle, rg.Vector3d.YAxis, startPnt)
shape.Transform(xform)

# move the rail's seam to the shape's starting point
rc, t = rail.ClosestPoint(startPnt)
rail.ChangeClosedCurveSeam(t)

breps = rg.Brep.CreateFromSweepSegmented(rail, shape, False, sc.doc.ModelAbsoluteTolerance)

sc.doc.Objects.AddCurve(rail)
sc.doc.Objects.AddCurve(shape)
for brep in breps:
    sc.doc.Objects.AddBrep(brep)
sc.doc.Views.Redraw()

– Dale

2 Likes

Yes. It does. Changing the curve seam also fixes it in GH. It’s something we don’t normally have to worry about when just using Rhino.

Thank you!

Edit: I did some tests on the circle, and it seems the curve seam is also important for sweeps where the rail is a circle in both python and GH, but by coincidence it was lining up with my cross-section shape in the circle’s case.

And, sorry to pester you, but what does “rc” mean here?

rc, t = rail.ClosestPoint(startPnt)

Thanks for your suggestions @0904. What I was trying to do is figure out how to use the python commands, and I couldn’t figure out how this particular command (Sweep1) worked. And then I noticed it also didn’t work in Grasshopper either.

It turns out it has to do with the curve seam. So sweeps in python and grasshopper need to account for the position of the rail’s curve seam, which is something we don’t have to worry about when we’re just using Rhino’s sweep1 tool.

:+1:


try this (with the mouse, first left button then right button):

import Rhino as rh
rc, pt = rh.Input.RhinoGet.GetPoint(“Point”, False)
print rc, pt

rc is the first output value equivalent to the result of the command

while pt is the second one which is equivalent to the actual point

1 Like

Generally “return code” or “result code”.

– Dale

1 Like