Sweep Tool

The multiSweep script allows for the selection of multiple rails and a profile from which the profile’s relative planar orientation is determined and automatically aligned perpendicular to each rail. The interface and options for this version are very basic and later versions will become much more robust.  This version of the sweep tool allows for multiple selections of rails and multiple selection of profiles. Initial rotation of profiles will loop until the desired rotation angle is specified.

Rhino Script

Option Explicit
'Script written by <David Mans>
'Script copyrighted by <NeoArchaic Design>
'Script version Thursday, March 13, 2008 4:36:59 PM

Call Main()
Sub Main()
	Dim rails,profile,i
	rails = Rhino.GetObjects("Select Rail Curves", 4)
	If isNull(rails) Then Exit Sub
	profile = Rhino.GetObjects("Select Profile Curves in Order of Placement", 4)
	If isNull(profile) Then Exit Sub
	
	Call Rhino.EnableRedraw(False)
	For i = 0 To uBound(rails) Step 1
		Call reparameterize(rails(i))
	Next
	Call Rhino.EnableRedraw(True)
	
	Call curveSweepMultiProf(rails, profile)
End Sub
Function curveSweepMultiProf(rail, profile)
	curveSweepMultiProf = Null
	
	Dim i,j,k,angle,pCount,Count
	Count = uBound(rail)
	pCount = uBound(profile)
	'profile variables
	Dim bBox(), oriPts(), dist(2), edgeLine(1), originPts(2),originPln, midline
	ReDim bBox(pCount), oriPts(pCount)
		
	'create an origin plane for the profile
	Call Rhino.EnableRedraw(False)
	For j = 0 To pCount Step 1
		bBox(j) = Rhino.BoundingBox(profile(j))
		dist(0) = Rhino.Distance(bBox(j)(0), bBox(j)(2))
		dist(1) = Rhino.Distance(bBox(j)(0), bBox(j)(5))
		dist(2) = Rhino.Distance(bBox(j)(0), bBox(j)(7))
	
		If dist(0) > dist(1) And dist(0) > dist(2) Then
			k = array(0, 1, 2)
		ElseIf dist(1) > dist(0) And dist(1) > dist(2) Then
			k = array(0, 1, 5)
		ElseIf dist(2) > dist(1) And dist(2) > dist(0) Then
			k = array(0, 3, 7)
		End If
		edgeLine(0) = Rhino.AddLine(bBox(j)(k(0)), bBox(j)(k(1)))
		edgeLine(1) = Rhino.AddLine(bBox(j)(k(1)), bBox(j)(k(2)))
		midline = Rhino.AddLine(bBox(j)(k(0)), bBox(j)(k(2)))
		originPts(2) = Rhino.CurveMidPoint(midline)
	
		originPts(0) = Rhino.CurveMidPoint(edgeLine(0))
		originPts(1) = Rhino.CurveMidPoint(edgeLine(1))
		originPln = Rhino.PlaneFromPoints(originPts(2), originPts(0), originPts(1))
		Call Rhino.DeleteObjects(edgeLine)
		Call Rhino.DeleteObject(midline)
		oriPts(j) = originPts
	Next
	
	'create alignment planes on the curve
	'rail variables
	Dim crvDom,crvStep, crvPlane(),crvProf(),crvPt(2)
	ReDim crvPlane(Pcount),crvPlaneSet(count),crvProfSet(count),crvProf(Pcount)
	For i = 0 To count Step 1
		crvDom = Rhino.CurveDomain(rail(i))
		If Pcount = 0 Then
			crvStep = 0
		Else
			crvStep = crvDom(1) / Pcount
		End If
		For j = 0 To Pcount Step 1
			crvPlane(j) = Rhino.CurvePerpFrame(rail(i), j * crvStep)
			crvPt(0) = crvPlane(j)(0)
			crvPt(1) = Rhino.pointadd(crvPlane(j)(0), crvPlane(j)(1))
			crvPt(2) = Rhino.pointadd(crvPlane(j)(0), crvPlane(j)(2))
			crvProf(j) = Rhino.OrientObject(profile(j), array(oriPts(j)(2), oriPts(j)(1), oriPts(j)(0)), array(crvPt(0), crvPt(1), crvPt(2)), 1)
		Next
		crvPlaneSet(i) = crvPlane
		crvProfSet(i) = crvProf
	Next
	'allow for rotation correction
	Call Rhino.EnableRedraw(True)
	angle = 90
	Do Until angle = 0
		angle = Rhino.GetReal("Object Rotation", 0, 0, 360)
		If isNull(angle) Then Exit Do
		Call Rhino.EnableRedraw(False)
		For i = 0 To count Step 1
			For j = 0 To Pcount Step 1
				Call Rhino.RotateObject(crvProfSet(i)(j), crvPlaneSet(i)(j)(0), angle, crvPlaneSet(i)(j)(3))
			Next
		Next
		Call Rhino.EnableRedraw(True)
	Loop
	
	Call Rhino.EnableRedraw(False)
	
	'sweep variables
	Dim swProfSet(),strProfSet
	ReDim swProfSet(Pcount)
	
	'call out sweep command
	For i = 0 To count Step 1
		For j = 0 To Pcount Step 1
			swProfSet(j) = ("_SelID " &amp; crvProfSet(i)(j) &amp; " ")
		Next
		strProfSet = Join(swProfSet)
		'swPprofSet 
		Call Rhino.Command("-_Sweep1 " &amp; "_SelID " &amp; rail(i) &amp; " " &amp; strProfSet &amp; " _Enter _Enter _Simplify=None Enter", False)
	Next
	Call Rhino.EnableRedraw(True)

	curveSweepMultiProf = array()
End Function
Function reparameterize(strObjectID)
	If Rhino.IsCurve(strObjectID) = True Then
		Call rhino.SelectObject(strObjectID)
		Call rhino.Command("reparameterize 0 1", False)
		Call rhino.UnselectAllObjects()
	End If
	If Rhino.IsSurface(strObjectID) = True Then
		Call rhino.SelectObject(strObjectID)
		Call rhino.Command("reparameterize 0 1 0 1", false)
		Call rhino.UnselectAllObjects()
	End If		
End Function