Monday, November 26, 2007

orientCurve














The following is the script to construct this mess. I modeled a polygon lattice in Maya with multiple deformer. In Rhino, the script allows me to select those lines in order to lay them out. I printed those lines and cut wood sticks accordingly.

NO measuring! Saved my ass.














Option Explicit
Sub orientCurve

Dim strLine, i, arrReference, arrTarget
Dim strCurveS, strCurveE, strTarget1, strTarget2
i = 4

Do

'select lines in order
strLine = Rhino.GetObject ("select a line", 4)

'orient lines
strCurveS = Rhino.CurveStartPoint (strLine)
strCurveE = Rhino.CurveEndPoint (strLine)

arrReference = Array (strCurveS,strCurveE)
strTarget1 = Array (0,-i, 0)
strTarget2 = Array (99999,-i, 0)
arrTarget = Array (strTarget1,strTarget2)

i = i + 0.25
Call Rhino.OrientObject (strLine, arrReference, arrTarget)

Loop

End Sub
orientCurve


Monday, October 15, 2007

Population Script


















This Script takes a bunch of lines and populates another curve to them. Recommended for lasercut.






Option Explicit

Call Populate()
Sub Populate()

Dim Object, ArrLines, i, Popstart, PopEnd, RefPoints, strScale, strOptions, RefObject

strOptions = Array ("y", "n")


Object = Rhino.GetObject ("Select Populate Object", 4)
RefObject = Rhino.GetObject ("Select Reference line for Population", 4)
ArrLines = Rhino.GetObjects ("Select target Curves", 4)
strScale = Rhino.GetString ("Do you want to Scale", "y", strOptions)

Popstart = Rhino.CurveStartPoint(RefObject)
PopEnd = Rhino.CurveEndPoint(RefObject)
RefPoints = Array(Popstart, Popend)

For i = 0 To UBound(arrLines)
Call Copypop(Object, arrlines(i), Refpoints, strScale)
Call Rhino.DeleteObject(arrlines(i))
Next

End Sub


Function CopyPop(Object, Target, Refpoints, strScale)

Dim startPoint, endPoint, TargetPoint, PopCurve, tempCrv, refDist

startPoint = Rhino.CurveStartPoint(target)
endPoint = Rhino.CurveEndPoint(target)
TargetPoint = Array(startPoint, endPoint)
refDist = Rhino.Distance (Refpoints(0), RefPoints(1))


If strScale = "n" Then
Dim targetDist, scalefactor
targetDist = Rhino.Distance(TargetPoint(0), TargetPoint(1))
scalefactor = TargetDist/Refdist
tempCrv = Rhino.ScaleObject(Object, RefPoints(0),Array(scalefactor,1,1) ,vbTrue)
PopCurve = Rhino.OrientObject(TempCrv, RefPoints, TargetPoint)

Else
PopCurve = Rhino.OrientObject(Object, RefPoints, TargetPoint, 3)
End If

End Function

Thursday, October 4, 2007

Still having a bug

Ok Sky, I removed the bug, no more error message, but when I try hiding objects, command cannot grab anything. Array after sorting is name-string array, not object-string array.

Another problem is that since SortStrings reads CurveLength number as string...
Array (32, 9,12,11, 25)
Sorted Array (11, 12, 25, 32, 9)

I guess I'll go back to my studio now...



Option Explicit

ShowCurve ()
Sub ShowCurve ()

Dim arrCurve, arrSorted, strTemp, i

'Get The Curves
arrCurve = Rhino.GetObjects ("select curves to rename", 4)

'Assign Curves to new array and rename objects
For i = 0 To UBound(arrCurve)
If Rhino.IsCurve(arrCurve(i)) Then

strTemp = Rhino.CurveLength(arrCurve(i))
arrCurve(i) = Rhino.ObjectName (arrCurve(i), "Curve" & CStr(strTemp))
Rhino.Print (arrCurve(i))
Rhino.Sleep 300

End If
Next

'Sort lengths in ascending order
arrSorted = Rhino.SortStrings(arrCurve, True)

'Hide all Objects
'Rhino.Command ("SelAll")
'Rhino.Command ("Hide")
Rhino.HideObjects (arrSorted)

'Show the Objects in curve length order
For i = 0 To UBound(arrSorted)

strTemp = arrSorted(i)
Rhino.ShowObject (strTemp)
Rhino.Print "sorted:" & (arrSorted(i))
Rhino.Sleep 300

Next

End Sub

SineWave

Today's Script: Generate a sine wave, create spheres and scale them in order.













Option Explicit
'draw a sine wave using points

SineWave()
Sub SineWave()

Dim x, y, dblA, dblB, arr, dblStep, arrPoint(), arrSphere(), i, A, B, C
dblA = 0
dblB = 12
dblStep = 0.25
i = 0

For x = dblA To dblB Step dblStep
y = 2*Sin(x)

A = 0.02*i
B = 0.02*i
C = 0.03*i
arr = Array(A, B, C)

Call Rhino.AddPoint (Array (x,y,0))
ReDim Preserve arrPoint(i)
arrPoint(i) = Array (x,y,0)

ReDim Preserve arrSphere(i)
arrSphere(i) = Rhino.AddSphere (Array (x,y,0), 0.25)

Call Rhino.ScaleObject (arrSphere(i), arrPoint(i), arr)


Call Rhino.Sleep(30)
i = i+1
Next

End Sub

Tuesday, October 2, 2007

Show Curves in Order of Length

For some reason I can't debug this code. Has problems with sortnumber variable type. Can anyone figure this out?


Option Explicit

ShowCurve ()

Sub ShowCurve ()

Dim arrCurve, i, arr(), temp, arr2()

'Get The Curves
arrCurve = Rhino.GetObjects ("select a curves to evaluate", 4)

'Assign Curves to new array and rename objects
For i = 0 To UBound(arrCurve)
If Rhino.IsCurve(arrCurve(i)) Then
temp = Rhino.CurveLength(arrCurve(i))
Rhino.Print (temp)
ReDim Preserve arr(i)
arr(i) = temp
Rhino.ObjectName arrCurve(i), "Curve" & CStr(temp)
End If
Next

'Sort lengths in ascending order
arr2 = Rhino.SortNumbers(arr, vbTrue)

'Hide all Objects
Rhino.Command ("SelAll")
Rhino.Command ("Hide")

'Show the Objects in curve length order
For i = 0 To UBound(arr2)
Temp = CStr(arr2(i))
Rhino.ShowObject "Curve" & Temp
Rhino.Sleep 1000
Next

End Sub

Monday, October 1, 2007

CurveToFitArea















On the right is a script I wrote to scale down a curve to fit in certain area. The original is CurveToFitLength in Rhino scripting tutorial. Knowing both INPUTs

Rhino.CurveLength (strObject)
Rhino.CurveArea (strObject)

were available in Scripting Method, I thought it would be easy to write the same script but Area-based scaling instead of Length-based scaling. But I just realized Scripting Method also requires me to refer the OUTPUT. Unfortunately, CurveLength has dbl OUTPUT while CurveArea has arr OUTPUT.

Checkout the difference in above jpg.

Sunday, September 30, 2007

Array To Select Multiple Curves

Selecting multiple objects is easy, just use the Rhino.GetObjects method which returns an array, then cycle through the array to check each curve

Dim arrCurve, intShort

intShort = Rhino.GetReal ("min. length to keep?", 0.1)
arrCurve = Rhino.GetObjects ("select a curves to evaluate", 4)

Dim i

For i = 0 to Ubound(arrCurve)
If Rhino.CurveLength (arrCurve(i)) > intShort Then
Call Rhino.ObjectLayer (arrCurve(i), "Curve")
Else
Call Rhino.DeleteObject (arrCurve(i))
End If
Next

Newbie's struggle

Inspired from the script Sky wrote last night, I would like to write a script that lets user select many curves and decides the min. length to keep, and deletes shorter-than-the-min. curves. My struggle is that CurveLength (script method) seems to evaluate only ONE curve at a time. If someone know how to do it better, please let me know. array still confuses me.


Option Explicit

EvaluateCurve ()
Sub EvaluateCurve ()

Call Rhino.AddLayer ("Curve")

Dim strCurve, intShort
intShort = Rhino.GetReal ("min. length to keep?", 0.1)
strCurve = Rhino.GetObject ("select a curve to evaluate", 4)

If Rhino.CurveLength (strCurve) > intShort Then
Call Rhino.ObjectLayer (strCurve, "Curve")
Else
Call Rhino.DeleteObject (strCurve)
End If

End Sub

Pattern Generation


What was seemingly a simple script took me all night to figure out. It takes any curve and divides it up into alternating sets of cut lines to be pulled out into perforated structures.





Option Explicit

Call CutPattern ()

Sub CutPattern ()

Dim blspace, varcut, arrOddCrv, arrEvenCrv, offset, temp

'get User Input

blspace = Rhino.GetReal ("size of space",.1, 0, .5)
varCut = Rhino.GetInteger ("Number of cuts",20)
offset = Rhino.GetReal ("Offset Amount", 1, 0, 1)
arrOddCrv = Rhino.GetObjects ("Pick Odd Curves", 4)
arrEvenCrv = Rhino.GetObjects ("Pick Even Curves", 4)
temp = 0

Dim k

For k = 0 To UBound(arrOddCrv)
Call Generate(arrOddCrv(k), blspace, varcut, temp)
Next

For k = 0 To UBound(arrEvenCrv)
Call Generate(arrEvenCrv(k), blspace, varcut, offset)
Next

End Sub

Function Generate(strCrv, BetweenCuts, CutNum, offset)

Dim Counter : Counter = 0
Dim Dist : Dist = 0
Dim ArrPoints(), ArrDomain, currentDist, adjSpace, adjCut
arrDomain = Rhino.CurveDomain(strCrv)
adjSpace = 1/CutNum*BetweenCuts
adjCut = ((1/CutNum)-adjSpace)*.5
dist = dist + (adjcut*offset)
'Rhino.Print "Curve domain: " & CStr(arrDomain(0)) & " to " & CStr(arrDomain(1))


Do While Dist < 1
ReDim Preserve arrPoint(counter)
currentDist = adjPar(arrDomain, dist)
arrPoint(counter) = Rhino.EvaluateCurve(strCrv, currentDist)
dist = dist + adjCut
Counter = counter + 1

ReDim Preserve arrPoint(counter)
currentDist = adjPar(arrDomain, dist)
arrPoint(counter) = Rhino.EvaluateCurve(strCrv, currentDist)
dist = dist + adjCut
Counter = counter +1

ReDim Preserve arrPoint(counter)
currentDist = adjPar(arrDomain, dist)
arrPoint(counter) = Rhino.EvaluateCurve(strCrv, currentDist)
dist = dist + adjSpace
Counter = counter +1
Loop

Dim i : i = 0
Dim LineArray(2)

'Add Lines
Do While i < UBound(arrPoint)
LineArray(0) = arrPoint(i)
i=i+1
LineArray(1) = arrPoint(i)
i=i+1
LineArray(2) = arrPoint(i)
i=i+1
Rhino.AddCurve LineArray
Loop

End Function

Function adjPar(crvDomain, dist)
adjPar = crvDomain(0) + dist * (crvDomain(1) -crvDomain(0))
End Function

Saturday, September 15, 2007

pariSSSS, france

Last spring, while attending a semester at the Ecole Speciale D'Architecture the studio was introduced to rhino scripting techniques at a workshop conducted by Edmondo Occhipinti. The studio ; Eco-Logical High-rise, focused around the idea of utilizing various computational methods and software for design performance, evaluation, and optimization.

This script was developed in collaboration with Martin. It creates a series of 12 points from equations derived for the construction of a unit circle, implements a directional deviation of either a single or double point, and draws a closed curve through the set of points. The script was used to generate floor plates that respond to prevalent wind direction, either by developing a 'bulge factor' in the direction of the wind or against it. It was imagined that the implementation of this method in the design could be used to have parts of the building that were capturing the wind for energy-generation purposes and others that were repelling the wind for structural reasons.

Voici le script et quelques images:



















Option Explicit
'base floor curve from points'

Call DrawCurve


Sub DrawCurve

Dim r
Dim bulgefactor
Dim i
Dim j
Dim arrpt1, arrpt2, arrpt3, arrpt4, arrpt5, arrpt6, arrpt7, arrpt8, arrpt9, arrpt10, arrpt11, arrpt12
Dim arrpts
Dim arrcrvpts
Dim crv1

bulgefactor= Rhino.getreal ("choose bulge ratio")
r= 1.0477787091366303436714165968148*Rhino.getreal ("identify RADIUS", 1,0)
i= ((3/2)*Rhino.getreal ("choose the inflatement ratio for ETE", bulgefactor,-2))/1.0477787091366303436714165968148
j= ((3/2)*Rhino.getreal ("choose the inflatement ratio for HIVER", -bulgefactor,-2))/1.0477787091366303436714165968148


arrpt1= array (0,r)
arrpt2= array ((r+i*r)/2,(r+i*r)*Sqr(3)/2)
arrpt3= array (r*Sqr(3)/2, r/2)
arrpt4= array (r,0)
arrpt5= array (r*Sqr(3)/2, -r/2)
arrpt6= array (r/2, -r*Sqr(3)/2)
arrpt7= array (0,-(r+j*r))
arrpt8= array (-r/2, -r*Sqr(3)/2)
arrpt9= array (-r*Sqr(3)/2, -r/2)
arrpt10= array (-r,0)
arrpt11= array (-r*Sqr(3)/2, r/2)
arrpt12= array (-r/2, r*Sqr(3)/2)

arrpts= array (arrpt11, arrpt12, arrpt1, arrpt2, arrpt3, arrpt4, arrpt5, arrpt6, arrpt7, arrpt8, arrpt9, arrpt10, arrpt11)

'arrcrvpts= Rhino.addpoints (arrpts)

crv1= Rhino.AddCurve (arrpts,3)



End Sub