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

Wednesday, February 28, 2007

Advanve Structure









Power Copying...








Here are some iterations of origami surfaces. The challenge was (except the manual powerCopying...) how to set up spikes NORMAL to the surface. Basically, those are done by manipulating sin curve functions (to control the curvature of surfaces). Deformation nodes are the followings.

-the span of sin curve
-number of waves
-repetition of waves
-height of the creases
-acceleration of curvature angle (by law)

The next step is to apply scaling to those creases. Well, actually those steps are similar to the physical origami studies from my 3A studio.

By the way, I think FoG stands for Function of Graph. Better guess than Frank O Gehry...

Tuesday, February 13, 2007

Exporting Points











Right now my job at Arup is to do solar gain calculations on a house. In order to do this I have to model the window and the shading devices in the Arup engineering software. Unfortunately engineering software is not very visual, meaning that all the shading planes have to be entered via coordinates like x, y, z. The project I'm working on has hundreds of these shading planes, to do the job manually would take several days of tedious calculations and data entry. So I wrote a little script to export all the points from a 3d rhino model to a spreadsheet in which the whole thing can be pasted into the program with one button. This saves hours of tedious time and gives me the benefit of using Rhino to make the 3d model which is extremely fast.

Here's the script:

Option Explicit

PrintSurfacePoints

Sub PrintSurfacePoints


Dim strSurface, arrObjects
arrObjects = Rhino.GetObjects("Select surfaces", 8)
If IsNull(arrObjects) Then Exit Sub

Dim i : i = 0
Dim surfaceArray()

If IsArray(arrObjects) Then

For Each strSurface In arrObjects


Dim arrPoints
arrPoints = Rhino.SurfacePoints(strSurface)
If Not IsArray(arrPoints) Then Exit Sub

ReDim Preserve surfaceArray(i)
surfaceArray(i) = arrPoints
i = i+1

Next

End If

Dim objXL
Set objXL = CreateObject("Excel.Application")


objXL.Visible = True
objXL.WorkBooks.Add


objXL.Columns(1).ColumnWidth = 10
objXL.Columns(2).ColumnWidth = 10
objXL.Columns(3).ColumnWidth = 10
objXL.Columns(4).ColumnWidth = 10
objXL.Columns(5).ColumnWidth = 10
objXL.Columns(6).ColumnWidth = 10
objXL.Columns(7).ColumnWidth = 10

objXL.Cells(1, 2).Value = "Base X"
objXL.Cells(1, 3).Value = "Base Y"
objXL.Cells(1, 4).Value = "Base Z"
objXL.Cells(1, 5).Value = "Top X"
objXL.Cells(1, 6).Value = "Top Y"
objXL.Cells(1, 7).Value = "Top Z"


objXL.Range("A1:G1").Select
objXL.Selection.Font.Bold = True
objXL.Selection.Interior.ColorIndex = 1
objXL.Selection.Interior.Pattern = 1 'xlSolid
objXL.Selection.Font.ColorIndex = 2


objXL.Columns("B:B").Select
objXL.Selection.HorizontalAlignment = &hFFFFEFDD ' xlLeft

Dim intIndex
intIndex = 2

Dim d
For d = 0 To i-1 Step 1

Dim strPoint, arrPt
Dim counter: counter = 0

For counter = 0 To 2 Step 2
arrPt = surfaceArray(d)(counter)
objXL.Cells(intIndex, 2).Value = Round(arrPt(0),4)
objXL.Cells(intIndex, 3).Value = Round(arrPt(1),4)
objXL.Cells(intIndex, 4).Value = Round(arrPt(2),4)
arrPt = surfaceArray(d)(counter+1)
objXL.Cells(intIndex, 5).Value = Round(arrPt(0),4)
objXL.Cells(intIndex, 6).Value = Round(arrPt(1),4)
objXL.Cells(intIndex, 7).Value = Round(arrPt(2),4)
objXL.Cells(intIndex, 8).Value = 100
objXL.Cells(intIndex, 9).Value = 0

objXL.Cells(intIndex, 1).Value = "surface " & d+1
intIndex = intIndex + 1
Next

Next

objXL.UserControl = True

End Sub

Saturday, January 27, 2007

DrawLineFromCurve










The following is pretty basic script to take a curve to generate a straight line that has the same length with the original curve.



Option Explicit
'this script is created to unroll sphere
'so that hopefully I chould unroll little bit advanced shape.


UnrollSphere()
Sub UnrollSphere()

'Shpere should be ready
' -Circumference Max is 8'
' -Trimmed with 0 and 45 degree lines
' -Rebuilt Vertical Surf to U2, Vt
' -Extract wireframe



'Number of Division
Dim t
t = 8

Dim arrOrigin
arrOrigin = array(0,0,0)



'Get Length
Dim halfSphereCircumference1, dblLength

halfSphereCircumference1 = Rhino.GetObject("Select a circumference curve", 4)
If IsNull(halfSphereCircumference1) Then Exit Sub

dblLength = Rhino.CurveLength(halfSphereCircumference1)
Rhino.Print "Curve length: " & CStr(dblLength)




'Draw Line and Divide
Dim strStraight, arrCircumferenceCurvePoints

strStraight = Rhino.AddLine (arrOrigin, array(0,dblLength,0))



End Sub



Friday, January 26, 2007

Script Samples

If you are trying to veryfy whether or not the selected object is curve, don't use IsCurve.

Rhino.IsCurve (strObject [, intIndex])

It would be much faster if you use GetObject instead.

Rhino.GetObject ([strMessage [, intType [, blnPreSelect [, blnSelect [, arrObjects ]]]]])

The Second option [, intType lets you limit the type of object you can select.
The object types are the following

0
1
2
4
8
16
32
256
512
4096

Monday, January 15, 2007

Digital Project




Hope the Rhinoscripting is going good. I just sat through a presentation of Digital project. The program seems amazing and is totally compatible with visual basic, which is good for all of us that started learning. From what Nick Pisca said the plus of Digital Project is its stability, and of course real time parametric updating that rhino doesn't have. Also turns out a lot of other programs can be accessed through windows platform. I don't know the specifics of it but really its this real-time, network, cross-program workflow that is fascinating.

All Things BIM has a post about Digital Project.

Friday, January 12, 2007

minimal surface script

// minimum surface creator.
// copyright 2005 Theo Calvin
// free to use for educational purposes.
// for any other use please contact theo@mediumlite.com


minSurfUI;

/////////////////////////////////////////////////////////////////////////////////////

proc string[] parseName (string $input) {
string $return[];
string $next;
string $currentString = "";
int $strCount = 0;
for ($i=2; $i<=`size($input)`; $i++) { $next = `substring ($input) $i $i `; if ($next == "|") { $return[$strCount] = $currentString; $currentString = ""; $strCount++; } else { $currentString = $currentString + $next; } if ($i == `size($input)`) { $return[`size($return)`] = $currentString; } } return $return; } ///////////////////////////////////////////////////////////////////////////////////// proc vector getLocV(string $one){ float $currentpos[] = `xform -ws -q -t ($one)`; return <<$currentpos[0],$currentpos[1],$currentpos[2]>>;
}


// ================================================================================
//
// minSurf
//
// ================================================================================

global proc minSurf() {
waitCursor -state on;
float $curveMin;
float $curveMax;
float $curveSpan;
int $updatePercentage ;
float $smoothLoops;
float $updateAmmount;

progressWindow
-title "Creating Surface"
-status ("Complete: "+$updatePercentage+"%")
-isInterruptable true;
;

//........................
// get selection
//........................
string $curves[] = `ls -sl -l`;
string $path[] = parseName ($curves[0]);

//........................
// create polySurface
//........................
int $minSXarray[] = `intFieldGrp -q -v polySubX_field`;
int $minSYarray[] = `intFieldGrp -q -v polySubY_field`;
int $minSX = $minSXarray[0];
int $minSY = $minSYarray[0];
string $minSholder[] = `polyPlane -w 1 -h 1 -sx $minSX -sy $minSY -ax 0 1 0 -tx 1 -ch 0 -n "minSurface"`;
string $minS = $minSholder[0];

//...............................
// place edges on borders (x1)
//...............................
$curveMin = `getAttr ($curves[0]+".min")`;
$curveMax = `getAttr ($curves[0]+".max")`;
$curveSpan = `abs $curveMax`-`abs $curveMin`;
float $subSpan = $curveSpan/$minSX;


float $currentU;
float $pointLoc[];
for ($i=0; $i<=$minSX; $i++) { $currentU = $curveMin + ( $subSpan*$i); $pointLoc = `pointOnCurve -pr $currentU $curves[0]`; select -r ($minS+ ".vtx["+$i+"]") ; move $pointLoc[0] $pointLoc[1] $pointLoc[2] ; //currentTime 0; } //............................... // place edges on borders (y1) //............................... $curveMin = `getAttr ($curves[1]+".min")`; $curveMax = `getAttr ($curves[1]+".max")`; $curveSpan = `abs $curveMax`-`abs $curveMin`; float $subSpan = $curveSpan/$minSY; int $vtx; for ($i=1; $i<$minSY; $i++) { $vtx = $minSX +($i*($minSX+1)); //print ("vtx: " + $vtx + "\n"); $currentU = $curveMin + ( $subSpan*$i); $pointLoc = `pointOnCurve -pr $currentU $curves[1]`; select -r ($minS+ ".vtx["+$vtx+"]") ; move $pointLoc[0] $pointLoc[1] $pointLoc[2] ; //currentTime 0; } //............................... // place edges on borders (x2) //............................... $curveMin = `getAttr ($curves[2]+".min")`; $curveMax = `getAttr ($curves[2]+".max")`; $curveSpan = `abs $curveMax`-`abs $curveMin`; float $subSpan = $curveSpan/$minSX; for ($i=0; $i<=$minSX; $i++) { $vtx = ((($minSX+1)*($minSY+1))-1)-$i; $currentU = $curveMin + ( $subSpan*$i); $pointLoc = `pointOnCurve -pr $currentU $curves[2]`; select -r ($minS+ ".vtx["+$vtx+"]") ; move $pointLoc[0] $pointLoc[1] $pointLoc[2] ; //currentTime 0; } //............................... // place edges on borders (y2) //............................... $curveMin = `getAttr ($curves[3]+".min")`; $curveMax = `getAttr ($curves[3]+".max")`; $curveSpan = `abs $curveMax`-`abs $curveMin`; float $subSpan = $curveSpan/$minSY; for ($i=1; $i<$minSY; $i++) { $vtx = ((($minSX+1)*($minSY)))-($i*($minSX+1)); $currentU = $curveMin + ( $subSpan*$i); $pointLoc = `pointOnCurve -pr $currentU $curves[3]`; select -r ($minS+ ".vtx["+$vtx+"]") ; move $pointLoc[0] $pointLoc[1] $pointLoc[2] ; //currentTime 0; } //...................................... // place vertices into initial position //...................................... vector $v1; vector $v2; vector $v3; vector $v4; vector $new1; vector $new2; vector $pos; int $row; for ($i=($minSX+2); $i< ((($minSX+1)*$minSY)-1); $i++) { int $vMod = $i%($minSX+1); if ($vMod>0 && $vMod < $minSX) { $v1 = getLocV($minS+ ".vtx["+($i-$vMod)+"]"); $v2 = getLocV($minS+ ".vtx["+($i-$vMod+$minSX)+"]"); $v3 = getLocV($minS+ ".vtx["+($vMod)+"]"); $v4 = getLocV($minS+ ".vtx["+($vMod+(($minSX+1)*$minSY))+"]"); $new1 = (($v1*($minSX-$vMod))+($v2*$vMod))/$minSX; $row = $i/($minSX+1); $new2 = (($v3*($minSY-$row))+($v4*$row))/$minSY; $pos = ($new1 + $new2)*.5; select -r ($minS+ ".vtx["+$i+"]") ; move ($pos.x) ($pos.y) ($pos.z); //currentTime 0; } } int $vMod; $smoothLoops = `intSliderGrp -q -v maxIterationsField`; for ($loop=0; $loop<$smoothLoops ; $loop++) { for ($i=($minSX+2); $i< ((($minSX+1)*$minSY)-1); $i++) { $vMod = $i%($minSX+1); if ($vMod>0 && $vMod < $minSX) { //print (" " + $i); $v1 = getLocV($minS+ ".vtx["+($i-1)+"]"); $v2 = getLocV($minS+ ".vtx["+($i+1)+"]"); $v3 = getLocV($minS+ ".vtx["+($i-1-$minSX)+"]"); $v4 = getLocV($minS+ ".vtx["+($i+1+$minSX)+"]"); $pos = ($v1 + $v2 + $v3 + $v4)/4; select -r ($minS+ ".vtx["+$i+"]") ; move ($pos.x) ($pos.y) ($pos.z); } } select -r $minS; //print ("$loop: "+$loop+"\n"); if ( `progressWindow -query -isCancelled` ) break; $updateAmmount = ($loop/$smoothLoops )*100; $updatePercentage= $updateAmmount; //print ("$updatePercentage: " + ($updateAmmount) + "\n"); progressWindow -edit -progress ($updatePercentage) -status ("Complete: "+$updatePercentage+"%") ; if (`checkBox -q -v UIshowSurface`) { refresh -cv; } } progressWindow -endProgress; //print ("curveSpan: " + $curveSpan); select -r $minS; xform -cp; if (`size($path)`>2) {
parent ($minS) ($path[0]+"|"+$path[1]+"|"+$path[2]) ;
}
waitCursor -state off;
}

// ================================================================================
//
// minSurfUI
//
// ================================================================================

global proc minSurfUI () {
if (`window -exists minSurfUIWin` == 1) {
deleteUI minSurfUIWin;
}

string $minSurfUIWin = `window
-title "Minimum Surface Builder"
-menuBar 0
-mxb 0
-rtf 1
minSurfUIWin`;

//scrollLayout;
columnLayout;
separator -h 15 -w 400 -st "none";// whitespace
intFieldGrp -numberOfFields 1
-label "PolyDivisions X" -value1 15
polySubX_field; //`intFieldGrp -q -v polySubX_field`

intFieldGrp -numberOfFields 1
-label "PolyDivisions Y" -value1 15
polySubY_field; //`intFieldGrp -q -v polySubY_field`

// smoothing ITERATIONS
intSliderGrp -label "Smooth Iterations" -field true
-minValue 0 -maxValue 20
-fieldMinValue 0 -fieldMaxValue 100
-value 20
maxIterationsField; //`intSliderGrp -q -v maxIterationsField`


// show updates
separator -h 15 -w 400 -st "none";// whitespace
checkBox -label "Show Surface During Creation" -v 0 UIshowSurface;
/*
separator -h 15 -w 400 -st "in";// whitespace

text -l "0% Complete" UIupdateText;
*/

separator -h 15 -w 400 -st "in";// whitespace
// BUTTONS
//--------------
rowLayout
-nc 2
-cat 1 "both" 0
-cat 2 "both" 0
-columnWidth 1 100
-columnWidth 2 100
;

button -label "Create" -align "center" -command "minSurf";
button -label "Cancel" -align "center" -command "deleteUI minSurfUIWin";

showWindow $minSurfUIWin;
}


Friday, January 5, 2007

FitCurvetoLength Modified

























Here's Yuki's earlier script modified to identify the centerpoint of the curve with the method Rhino.BoundingBox



Option Explicit
'title: FitCurveToLength
'this script is to loop scaling a curve until it fits certain length

FitCurveToLength ()
Sub FitCurveToLength ()
Dim strCurveID
strcurveID = Rhino.GetObject("Select a curve to fit to length", 4, True, True)
If IsNull(strCurveID) Then Exit Sub

Dim arrBoundingBox
arrBoundingBox = Rhino.BoundingBox(strCurveID)

Dim arrCtr
Dim dblx, dbly, dblz
dblx =0.5*(arrBoundingBox(0)(0)+arrBoundingBox(1)(0))
dbly =0.5*(arrBoundingBox(1)(1)+arrBoundingBox(2)(1))
dblz =0.5*(arrBoundingBox(1)(2)+arrBoundingBox(5)(2))

arrCtr = array(dblx, dbly, dblz)

Dim dblLength
dblLength = Rhino.CurveLength(strCurveID)

Dim dblLengthLimit
dblLengthLimit = Rhino.GetReal("Length limit", 0.5*dblLength, 0.01*dblLength, dblLength)
If IsNull(dblLengthLimit) Then Exit Sub

Do
If Rhino.CurveLength(strCurveID) <= dblLengthLimit Then Exit Do
strCurveID = Rhino.ScaleObject(strCurveID, arrCtr, Array(0.95,0.95,0.95),True)
If IsNull(strCurveID) Then
Rhino.Print "Something went wrong..."
Exit Sub
End If
Loop

Rhino.Print "New curve length: " & Rhino.CurveLength(strCurveID)

End Sub

Thursday, January 4, 2007

Architectural Critique: Scripting Misuse

I found some Rhinoscripting studies while surfing the web that I was particularly disheartened with. The website shows a studio from Rensselaer Polytechnic Institute and what appears to be student projects in which math functions are the basis for structure/home design. Here are examples of what I DON'T want to do.

















Here we have math functions in their purity and complexity making singular forms that get transformed into buildings that simply don't work very well or would work much better if they were developed in different ways. Not to be too harsh but the above example simply works against the very premise of wild parametric design by including distinctly uniform and standard floor slabs. In addition, despite the variations that each student shows faded into the background the math functions aren't flexible for local conditions. What it amounts to is form exploration for its own sake, not for better design.

Granted this is all my superficial reaction to this work in that I haven't taken the time to read the studio premise or any individuals goal. But this is a blog and I get to say what I like. So step off.

Monday, January 1, 2007

DivideCurve ( ) _yuki















Here is my first script I wrote from scratch. User can pick two curves, divide into the number s/he wants, and draw lines accordingly. Array was complicated, but I'm getting hang of it.



Option Explicit
'S.S.S.S. sciarcsmac first challenge #2

DivideCurve()
Sub DivideCurve()
Dim strFirstCurve
strFirstCurve = Rhino.GetObject("Select the first curve", 4)
If IsNull(strFirstCurve) Then Exit Sub

Dim strSecondCurve
strSecondCurve = Rhino.GetObject("Select the second curve", 4)
If IsNull(strSecondCurve) Then Exit Sub


Dim t
t = Rhino.GetInteger("Number of division?", 10, 2, 100)
If IsNull (t) Then Exit Sub


Dim arrFirstCurvePoints
arrFirstCurvePoints = Rhino.DivideCurve(strFirstCurve, t, True)

Dim arrSecoudCurvePoints
arrSecoudCurvePoints = Rhino.DivideCurve(strSecondCurve, t, True)


Dim strAddedLines
Dim i


For i = 0 To t Step 1
strAddedLines = Rhino.AddLine(arrFirstCurvePoints(i), arrSecoudCurvePoints(i))

Next

Dim strSayYes
strSayYes = Rhino.GetString ("Continue? ", "Y")
If Not strSayYes = "Y" Then Exit Sub

Rhino.Print "Well done! "

End Sub

FitCurveToLength ( ) _yuki















So far, I just copied tutorial, but my challenge is to scale down the curve within the original. The example on the right is my goal. Now, the scale origin is set to (0,0,0). I have to change the scale origin to the center of gravity. I don't even know if there is a way to specify it.




Option Explicit
'title: FitCurveToLength
'this script is to loop scaling a curve until it fits certain length

FitCurveToLength ()
Sub FitCurveToLength ()
Dim strCurveID
strcurveID = Rhino.GetObject("Select a curve to fit to length", 4, True, True)
If IsNull(strCurveID) Then Exit Sub

Dim dblLength
dblLength = Rhino.CurveLength(strCurveID)

Dim dblLengthLimit
dblLengthLimit = Rhino.GetReal("Length limit", 0.5*dblLength, 0.01*dblLength, dblLength)
If IsNull(dblLengthLimit) Then Exit Sub

Do
If Rhino.CurveLength(strCurveID) <= dblLengthLimit Then Exit Do strCurveID = Rhino.ScaleObject(strCurveID, Array(0,0,0), Array(0.95,0.95,0.95),True)
If IsNull(strCurveID) Then
Rhino.Print "Something went wrong..."
Exit Sub
End If
Loop

Rhino.Print "New curve length: " & Rhino.CurveLength(strCurveID)

End Sub