Curve_growth (not working! -yet)

Option Explicit
‘Script written by Ado
‘Script copyrighted by archi.o.logies
‘Script version Monday, September 29, 2008 2:37:08 PM

‘WHAT THE HELL IS GOING ON WITH THIS VARIABLE DECLARATION?
‘Dim arrPtPoly()
Call Main()
Sub Main()
Dim inPt,inPtCoord, newPt
Dim arrPt()
Dim boud, boudbox, speed, radius
Dim n, j
Dim arrPtCoord()
Dim arrLines()
Dim arrPtPoly()

inPt = Rhino.GetObject(“Please pick initial point”,1,True)
If IsNull (inPt) Then Exit Sub
inPtCoord = Rhino.PointCoordinates(inPt)
n = Rhino.GetInteger(“Nr of iterations”,5,5)
boud = Rhino.GetObject(“please select boundary object”)
boudbox = Rhino.BoundingBox(boud)
speed = Rhino.GetInteger(“Speed”,5,5,10)
radius = Rhino.Distance(boudbox(0),boudbox(6))/speed

For j = 0 To n-1
Call RndPt (inPt, radius,j, n, boud, arrPtPoly)
Next
Rhino.Print(“i am so far2”)
‘——————————————————
‘QUESTION FOR MARK: HOW NOT TO HAVE AN ERROR HERE?????????
Rhino.AddPolyline(arrPtPoly)
‘——————————————————
End Sub

Function RndPt (inPt,radius,i,n, boud, arrPtPoly)

Dim inPtCoord, k
Dim alpha0, alpha1, alpha2, min
Dim Line
Dim intobjectType, strLayername

min = -radius

inPtCoord = Rhino.PointCoordinates(inPt)

alpha0 = arbitraryValue(min, radius)
alpha1 = arbitraryValue(min, radius)
alpha2 = arbitraryValue(min, radius)

‘Rhino.AddPoint array(0,0,inPtCoord(0))
ReDim Preserve arrPt(i)
arrPt(i) = Rhino.AddPoint (array(inPtCoord(0)+alpha0,inPtCoord(1)+alpha1,inPtCoord(2)))

ReDim Preserve arrPtPoly(i)
arrPtPoly(i) = Rhino.PointCoordinates(arrPt(i))
Rhino.Print Pt2Str(arrPtPoly(i))

If i>0 Then
k=i-1
‘——————————————————
‘MARK: HERE IT DOES NOT MAKE LINE BETWEEN 1ST AND 2ND POINTS
ReDim Preserve arrLines(k)
arrLines(k) = Rhino.AddLine (arrPtPoly(i), arrPtPoly(i-1))
‘——————————————————

‘USE CASES to call funtions according to objecttype(boud)
intObjectType = Rhino.ObjectType(boud)

Select Case intobjectType
Case 1, 2
strLayername = “Points”
inPt = arrPt(i)
Case 4
strLayername = “Curves”
inPt = arrPt(i)
Case 8
strLayername = “Surfaces”
inPt = arrPt(i)
Case 16
Call CSX (arrLines(k),boud, i, inPt, arrPt(i))
‘strLayername = “PolySurfaces”
Case 32
strLayername = “Meshes”
inPt = arrPt(i)
Case Else
strLayername = “Not suported object type, please enter (poly)surface/s”
End Select

If i = (n-1) Then
Rhino.Print(“i am so far 1…”)
Rhino.Print(“n is: ” & n & ” ||| i is :” & i)
‘Poly = Rhino.AddInterpCurve (arrPt)
End If

End If
‘inPt = arrPt(i)
End Function

Function arbitraryValue(min, max)
Randomize
arbitraryValue = Int((max – min + 1) * Rnd + min)
End Function

Function CSX (arrLines,boud,i,inPt, Pt)
Dim arrSrf
Dim arrCSX()
Dim l, m
Dim newPt

arrSrf = Rhino.ExplodePolysurfaces(boud,True)
If IsArray (arrSrf) Then
‘——————————————————
‘MARK: WHY DOES IT ONLY DO IT WITH THE FIRST SURFACE…????
For l=0 To Ubound(arrSrf)
ReDim Preserve arrCSX(l)
arrCSX(l) = Rhino.CurveSurfaceIntersection(arrLines, arrSrf(l))

If Not IsArray(arrCSX(l)) Then
Rhino.Print “Curve and surface ” & l & ” do not intersect.”
boud = Rhino.JoinSurfaces(arrSrf)
Rhino.DeleteObjects(arrsrf)
inPt = Pt
Rhino.AddText “Point number ” & i & “.” & vbCrLf & “ID: ” & inPt & “.” & vbCrLf & “Coordinates: ” & Pt2Str(Rhino.PointCoordinates(Pt)),Rhino.PointCoordinates(Pt),0.5,”arial”
Exit Function

Else
‘if the object intersects with the surface, then tell and do new point on surface instead of the calculated one
For m = 0 To UBound(arrCSX(l))
If arrCSX(l)(m,0) = 1 Then
Rhino.Print “Point”
Rhino.Print “Intersection point on curve: ” & Rhino.Pt2Str(arrCSX(l)(m,1))
Rhino.Print “Intersection point on surface: ” & Rhino.Pt2Str(arrCSX(l)(m,3))
Rhino.Print “Curve parameter: ” & CStr(arrCSX(l)(m,5))
Rhino.Print “Surface parameter: ” & CStr(arrCSX(l)(m,7)) & “,” & CStr(arrCSX(l)(m,8))
‘here we assign the new point to the variable for the line to be further made
newPt = Rhino.AddPoint (arrCSX(l)(m,1))
Else
Rhino.Print “Overlap”
Rhino.Print “Intersection start point on curve: ” & Rhino.Pt2Str(arrCSX(l)(m,1))
Rhino.Print “Intersection end point on curve: ” & Rhino.Pt2Str(arrCSX(l)(m,2))
Rhino.Print “Intersection start point on surface: ” & Rhino.Pt2Str(arrCSX(l)(m,3))
Rhino.Print “Intersection end point on surface: ” & Rhino.Pt2Str(arrCSX(l)(m,4))
Rhino.Print “Curve parameter range: ” & CStr(arrCSX(l)(i,5)) & ” to ” & CStr(arrCSX(l)(m,6))
Rhino.Print “Surface parameter range: ” & CStr(arrCSX(l)(i,7)) & “,” & CStr(arrCSX(l)(m,8)) & ” to ” & CStr(arrCSX(l)(m,9)) & “,” & CStr(arrCSX(l)(m,10))
End If
Pt = newPt
Next
End If
Next
End If
boud = Rhino.JoinSurfaces(arrSrf,True)
Rhino.DeleteObjects(arrsrf)
End Function


Curve_growth_not_working

Curve_growth_not_working

Advertisements

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