Showing posts with label Sky. Show all posts
Showing posts with label Sky. Show all posts

Sunday, March 16, 2008

Ball Tracking





Recently finished Nick Pisca's MEL scripting workshop and found MEL is a lot of fun. Seems much smarter than Rhino in a lot of ways. Things like declarations and arrays are much easier although the case sensitive stuff gets me all the time. We didn't cover procedures in the workshop but got to hit a lot of ground including scripting material assignment and rendering.


Here's a simple tracking script where planes duplicate and deform while following an animated object. I'll post the video sometime in the future.



//Tracking script
//
//Written by: Sky Milner
//Date: 3-03-08
//Contributor: Nick Pisca
//
//This script duplicates selected objects based on the
//location of a target.
//
//Setup:
//First make an object and call it "Target", Animate target as you like, make 6 nurbsPlanes
//
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



string $Selection[] = {"nurbsPlane1", "nurbsPlane2", "nurbsPlane2", "nurbsPlane3", "nurbsPlane3","nurbsPlane4","nurbsPlane4","nurbsPlane5","nurbsPlane5","nurbsPlane6", "nurbsPlane6","nurbsPlane1"};
int $SelSize = size($Selection);
int $SquareCounter = 0;

for ($i = 0; $i < currentnumber =" 0;" selectioncounter =" 0;" firstobject =" $Selection[$CurrentNumber];" secondobject =" $Selection[$CurrentNumber+1];" vecfirst =" <<$XYZfirst[0],">> ;

float $XYZsecond[] = `pointPosition ($SecondObject + ".cv [0] [0]")` ;
vector $VecSecond = <<$XYZsecond[0], $XYZsecond[1], $XYZsecond[2]>> ;

float $XYZtarget[] = `pointPosition ("Target.cv [0] [0]")`;
vector $VecTarget = <<$XYZtarget[0], $XYZtarget[1], $XYZtarget[2]>>;


$Between = $VecFirst - $VecSecond;

//Duplicate and move into position

duplicate -rr -n ("series"+$i+"square"+$SquareCounter) $Selection[($CurrentNumber)];

string $Duplicate = ("series"+$i+"square"+$SquareCounter);


//setAttr ($Duplicate+ ".translate") ($XYZfirst[0] + $Between.x/(-2)) ($XYZfirst[1] + $Between.y / (-2) ) ($XYZfirst[2] + $Between.z / (-2));

xform -r -t ($Between.x/(-2)) ($Between.y / (-2)) ($Between.z / (-2)) $Duplicate;


float $XYZduplicate[] = `pointPosition ($Duplicate + ".cv [0] [0]")`;
vector $Vecduplicate = <<$XYZduplicate[0], $XYZduplicate[1], $XYZduplicate[2]>>;

$Between2 = $VecTarget - $Vecduplicate;

//setAttr ($Duplicate+ ".translate") ($XYZduplicate[0] + $Between2.x/4) ($XYZduplicate[1] + $Between2.y/2) ($XYZduplicate[2] + $Between2.z/4);

xform -r -t ($Between2.x/4) ($Between2.y/2) ($Between2.z/4) $Duplicate;


//Scale Duplicate

float $scalefactor = ((mag($Between2)*.01)+.75);

//setAttr ($Duplicate+ ".scaleX") $scalefactor;
//setAttr ($Duplicate+ ".scaleY") $scalefactor;
//setAttr ($Duplicate+ ".scaleZ") $scalefactor;


//Manipulate cv[0]

float $PointX = `getAttr ($Duplicate + ".cv[0].xValue")`;
float $PointY = `getAttr ($Duplicate + ".cv[0].yValue")`;
float $PointZ = `getAttr ($Duplicate + ".cv[0].zValue")`;

vector $VecPoint = <<$PointX, $PointY, $PointZ>>;

$Between3 = $VecTarget - $VecPoint;

setAttr ($Duplicate+ ".cv[0].xValue") ($PointX + $Between3.x/(10));
setAttr ($Duplicate+ ".cv[0].yValue") ($PointY + $Between3.y/(10));
setAttr ($Duplicate+ ".cv[0].zValue") ($PointZ + $Between3.z/(10));

//setAttr ($Duplicate + ".objectColor") $SquareCounter;

$TempSelection [$SelectionCounter] = $FirstObject;
$TempSelection [$SelectionCounter+1] = $Duplicate;
$TempSelection [$SelectionCounter+2] = $SecondObject;
$TempSelection [$SelectionCounter+3] = $Duplicate;


$CurrentNumber = $CurrentNumber+2;
$SelectionCounter = $SelectionCounter + 4;
$SquareCounter++;
} while ($CurrentNumber < $SelSize); currentTime $i; $Selection = $TempSelection; $SelSize = size($Selection); if ($SelSize > 100) {
for ($s = 0; $s < selsize =" 100;" iii =" 0;" sizejump =" size($jump);" nicklambert = "nicklambert" nicklambertsg = "nicklambert" nicklambertoutcolor = "nicklambert" nicklambertsgss = "nicklambert" nicklamberttrans = "nicklambert" iiiend =" $iii" iiiend2 =" $iii" iii="$iii" i="0;" seriessize =" size($series);" s =" 0;" curshader =" $Shader[0];">

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

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

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

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

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

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.

Sunday, December 31, 2006

Area Script

















Here's a small script I wrote for calculating the area of panels in 3d. In the end I'd like to be able to send the information to a spreadsheet that will also flatten the panels and dimension them automatically.

Option Explicit

main()

Sub main()

Dim arrObjects

arrObjects = Rhino.GetObjects ("select a objects", 8)

Dim i
For i = 0 To UBound(arrObjects)
If Rhino.IsSurface(arrObjects(i)) Then
Dim arrArea : arrArea = Rhino.SurfaceArea(arrObjects(i))
Dim arrPoints : arrPoints = Rhino.SurfacePoints(arrObjects(i))
Rhino.AddText "Panel "& i+1 & " Area: " & CStr (arrArea(0)), arrPoints(0)
End If

Next

End Sub

Challenge #2 Method List (Please Update)

So following up on Yuki's proposal for Challenge #2 here is a list of methods we must use at least once in our script. Other restrictions are that we cannot use any other methods than the ones given. The goal should be to make the most useful/interesting/fun script using all the methods. Before the Challenge begins we should all contribute a method or two we'd like to use.

note *methods are built in commands and can be accessed by going to help - plugin - rhinoscript (in folder called methods)*

Method List for Challenge #2 (Maximum of 10)

Rhino.AddSrfPoint (Sky)
Rhino.GetPointOnSurface (Sky)

Rhino.CurveLength (Yuki)
Rhino.ScaleObject (Yuki)
Rhino.DivideCurve (Yuki)


Solution #1 (Sky)

I hope everyone's gotten started on your scripts. Here's my take on Challenge #1. Instead of starting with a panel I started with two curves. The user gets to input how many panels they want from 2 to 500 with the default value set at 10. To make this I used the tutorials along with the searching the method helpfiles. Working out the bugs with the nested arrays took a while. My original intent was to work in 2d and make ellipses that would span the two points on the curves with varying thickness. In the end I couldn't think of any other way than Rhino.command and that was giving me trouble.








































Here's the script:

Option Explicit

Call Main()

Sub Main
Dim t
Dim strCurve1, strCurve2
Dim arrCurve1Points(), arrCurve2Points()

t = Rhino.GetInteger("Number of Divisions",10,2,500)

Do
strCurve1 = Rhino.GetObject("Select First Curve",4)
If IsCurve(strCurve1) Then Exit Do
Loop

Do
strCurve2 = Rhino.GetObject("Select Second Curve", 4)
If IsCurve(strCurve2) Then Exit Do
Loop

Call AddPoints(strCurve1, t, arrCurve1Points)
Call AddPoints(strCurve2, t, arrCurve2Points)

Dim r
Dim arrTemp

For r = 0 To t-1 'line30
arrTemp = Array(arrCurve1Points(r), arrCurve1Points(r+1), arrCurve2Points(r+1), arrCurve2Points(r))
Call Rhino.AddSrfPt(arrTemp)
'Call Rhino.AddLine(arrCurve1Points(r), arrCurve2Points(r))
Next

End Sub

'This function makes an array of points on the selected curve
Function AddPoints(StrCurve, t, ByRef CurvePoints)

Dim arrDomain, dblParam, arrPoint

arrDomain = Rhino.CurveDomain(StrCurve)
dblParam = arrDomain(1)/t

Dim i
For i = 0 To t
arrPoint = Rhino.EvaluateCurve(StrCurve, dblParam * i)
ReDim Preserve CurvePoints(i)
CurvePoints(i) = arrPoint
'Call Rhino.AddPoint (arrPoint)
Next

End Function

Saturday, December 23, 2006

The Rhinoscript Challenge #1

Given that we're all Rhinoscript beginners the challenge was set up so that we could all work on one problem and compare our solutions.

Everyone got mad at me for making the first challenge several months ago so to make this as fair of a process let's all make suggestions to what the first challenge should be.

Why we need to learn Rhinoscript: A manifesto of sorts

Scripting in architecture, also known as computational design seems to be the current trend. So what's the big deal and why should we be a part of it?

In answering this question I'd like for us to come up with a new relevance for scripting in architecture, one that goes beyond form generation, or unique structure as we see at Sciarc. Already the division between scripting, parametric modeling, and B.I.M. software is going away to where they are all being connected into one big organizational software such as Generative Components, or Digital Project. This is very exciting in that never before has the designer played as much of a role as the designing software as they are now. Through scripting we are able to create the tools we want to use rather than picking from what the available software has to offer.

This is all good and as architects it will be necessary for us to know this stuff. My real beef is with what the prominent architects are doing with this new freedom. Around school what I see is a leaning toward complexity, complexity far beyond the capabilities of construction. What this means is that designs are visionary at best, mental masturbation at worst. You be the judge but it's safe to say that most of the projects proposed at Sciarc cannot be built tomorrow. This in as of itself is not a problem and I love to think in these big terms, but as a practical measure I want to also pursue scripting in terms of what it takes to get the job done. For those of you that saw the lecture by Roberto in 4A you know what I mean. Using scripting as a tool to simplify and automate the process. In the practicing environment this economy of speed and labour results in real savings, a way for us to actually make lots of money with our knowledge. This makes people that can script, i.e. us, a major component of any design & construction process.

I'd like to hear from those of you in Evan Douglas' studio to see your take on this stuff.

Here are several links to people already thinking about this.

The Yale Symposium <-- this is very interesting

The Gehry Method
A lecture that introduces concepts of BIM and Parametric Design

About the S.S.S.S.

The S.S.S.S. was formed as a way to help all of us exchange information about things pertaining to scripting, in particular Rhinoscripting. This blog is open for all members to post, update and edit, not only things about Rhinoscript but anything remotely related should be brought up.

For clarity we should put our name in the label of the post. That way we'll know who to respond to about certain topics.