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