arrange.multisweep.01

Option Explicit
‘Script written by
‘Script copyrighted by
‘Script version Thursday, March 13, 2008 4:36:59 PM

Call Main()
Sub Main()
Dim rails,profile,blnOrigin, 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

Dim bbox, tline, tpt, pt, arrPt()
ReDim arrPt(Ubound(profile))
For i = 0 To Ubound(profile) Step 1
Call Rhino.SelectObject(profile(i))
bbox = Rhino.BoundingBox(profile(i))
Call Rhino.EnableRedraw(False)
tline = Rhino.AddLine(bbox(0),bbox(2))
tpt = Rhino.CurveMidPoint(tline)
Call Rhino.DeleteObject(tline)
Call Rhino.EnableRedraw(True)

pt = Rhino.GetPoint(“Select Origin for Profile” & i,tpt)
Call Rhino.Command(“_SelNone”,False)

If isNull(pt) Then
arrPt(i) = tpt
Else
arrPt(i) = pt
End If
pt = Null
Next

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,arrPt)
End Sub
Function curveSweepMultiProf(rail,profile,arrOrigin)
curveSweepMultiProf = Null

Dim i,j,k,m,n,angle,pCount,Count
Count = uBound(rail)
pCount = uBound(profile)
‘profile variables
Dim bBox(), oriPts(), dist(2), originPts(2),originPln
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
m = array(1,0,0)
n = array(0,1,0)
ElseIf dist(1) > dist(0) And dist(1) > dist(2) Then
m = array(1,0,0)
n = array(0,0,1)
ElseIf dist(2) > dist(1) And dist(2) > dist(0) Then
m = array(0,1,0)
n = array(0,0,1)
End If

originPts(2)= arrOrigin(j)
originPts(0)= array(originPts(2)(0)+m(0),originPts(2)(1)+m(1),originPts(2)(2)+m(2))
originPts(1)= array(originPts(2)(0)+n(0),originPts(2)(1)+n(1),originPts(2)(2)+n(2))

originPln = Rhino.PlaneFromPoints(originPts(2),originPts(0),originPts(1))
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 ” & crvProfSet(i)(j) & ” “)
Next
strProfSet = Join(swProfSet)
‘swPprofSet
Call Rhino.Command( “-_Sweep1 ” & “_SelID ” & rail(i) & ” ” & strProfSet & ” _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

Advertisements

There are no comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: