Understanding PerformSweep vs CreateFromSweep and arrays


I am trying to do a sweep 2 rails with python, and understand it :cold_sweat:

This is what I got so far cobbling together bits from various searches here and the RhinoCommon SDK docs. Code:

import Rhino
import Rhino.Geometry as rg
import scriptcontext as sc
import rhinoscriptsyntax as rs

def Sweep2():
    rail1 = rs.GetObject("Select first rail curve", rs.filter.curve)
    rail_crv1 = rs.coercecurve(rail1)
    if not rail_crv1: return

    rail2 = rs.GetObject("Select second rail curve", rs.filter.curve)
    rail_crv2 = rs.coercecurve(rail2)
    if not rail_crv2: return

    cross_sections = rs.GetObjects("Select cross sections", rs.filter.curve)
    if not cross_sections: return
    cross_sections = [rs.coercecurve(crv) for crv in cross_sections]

    sweep = rg.SweepTwoRail()
    sweep.AngleToleranceRadians = sc.doc.ModelAngleToleranceRadians
    sweep.ClosedSweep = False
    sweep.SweepTolerance = sc.doc.ModelAbsoluteTolerance
    surface1 = sweep.PerformSweep(rail_crv1, rail_crv2, cross_sections)

if __name__ == "__main__":

The last error I was getting …

Can someone guide me a bit? looking here & here … still confused.

Thanks, «Randy


I think the problem might be this:

It returns a list of Breps, not a single Brep - so you would need to do something like the following:

sweep_result = sweep.PerformSweep(rail_crv1, rail_crv2, cross_sections)
if sweep_result:
   sweep_IDs= [sc.doc.Objects.AddBrep(srf) for srf in sweep_result]

I don’t know how a sweep2 rails could produce multiple Breps, but I guess it is assumed it could…



Excellent. Is the sweep_IDs returning a GUID?

The meaning of the square brackets, is that turning it into an array, like the error i got?

Thanks again,




obj_ID=sc.doc.Objects.AddBrep(brep) returns the GUID of the newly created object, that’s how you can identify what got added to the document.

sweep_IDs= [sc.doc.Objects.AddBrep(srf) for srf in sweep_result]

is a “List comprehension”, which is a shorthand for the following:

for brep in breps: sweep_IDs.append(sc.doc.Objects.AddBrep(brep))

It creates the list directly with an implied loop.

sweep_IDs should be a list of the returned object ID’s. I think it will be a list of only one ID most of the time, but it will be a list, not a single “naked” GUID.