Option Explicit
‘Script written by
‘Script copyrighted by
‘Script version Sunday, May 03, 2009 1:54:38 PM

Call Main()
Sub Main()
Dim Curves, SM, DN

Curves= Rhino.GetObjects(“Select Curves”,4)
If isNull(Curves) Then Exit Sub

SM = Rhino.GetBoolean(“Blend Type”,array(“Type”,”Straight”,”Smooth”),array(False))
If isNull(SM) Then Exit Sub

DN = Rhino.GetReal(“Blend Density”,5,1)
If isNull(SM) Then Exit Sub

Call Rhino.EnableRedraw(False)
If uBound(Curves) > 0 Then
Call BlendCurves(Curves,SM(0),DN)
Call Rhino.Print(“2 or more curves required”)
End If

Call Rhino.EnableRedraw(True)
End Sub
Function BlendCurves(arrCurves,blnSmooth,dblDensity)
BlendCurves = Null
Dim i,j,p
Dim count, max, dMax
Dim arrptCount(), arrCrvDeg(), arrPointSet(),arrPts(), arrCrvDom(),arrCrvStep(),arrBlndCrvPt()
Dim arrBlendCurve(), arrCtrlCrv()

Dim dblSmoothness
If blnSmooth = False Then
dblSmoothness = 1
dblSmoothness = 3
End If

count = Ubound(arrCurves)
ReDim arrptCount(count), arrCrvDeg(count), arrCrvDom(count), arrPointSet(count), arrPts(count)

‘get control point count
For i = 0 To count Step 1
arrptCount(i) = Rhino.CurvePointCount(arrCurves(i))
arrCrvDeg(i) = Rhino.CurveDegree(arrCurves(i))
‘determine max point count
max = Rhino.Max(arrptCount)
dMax= Rhino.Max(arrCrvDeg)

‘rebuild curves with max control point count
For i = 0 To count Step 1
Call Rhino.RebuildCurve(arrCurves(i),dMax, max)
arrPointSet(i) = Rhino.CurvePoints(arrCurves(i))

max = max-1
ReDim arrCtrlCrv(max), arrCrvDom(max), arrCrvStep(max), arrBlndCrvPt(max)
‘create control curves
For i = 0 To max Step 1
For j = 0 To count Step 1
arrPts(j) = arrPointSet(j)(i)
arrCtrlCrv(i)= Rhino.AddInterpCurve(arrPts,dblSmoothness)
arrCrvDom(i) = Rhino.CurveDomain(arrCtrlCrv(i))
arrCrvStep(i)= (arrCrvDom(i)(1)-arrCrvDom(i)(0))/(count*dblDensity)
‘create blended curves
ReDim arrBlendCurve(count*dblDensity)
For i = 0 To count*dblDensity Step 1
For j = 0 To max Step 1
arrBlndCrvPt(j) = Rhino.EvaluateCurve(arrCtrlCrv(j),arrCrvDom(j)(0)+i*arrCrvStep(j))
arrBlendCurve(i) = Rhino.addcurve(arrBlndCrvPt,dMax)
‘delete control curves
Call Rhino.DeleteObjects(arrCtrlCrv)
Call Rhino.DeleteObjects(arrCurves)

BlendCurves = array(arrBlendCurve,arrCtrlCrv)
End Function


There are no comments on this post.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: