‘ RhinoScript ’ category archive

Mar
24

Array/Orient Objects based on Two Surfaces

I’ve been trying to explore more with Rhino Explicit History and also with RhinoScript. Here’s a simple one that arrays basic object onto a surface and orients them to a target surface. It doesn’t deform the base object in any ways. It could be a useful tool in trying to create gradient patterns using just rotations without changing the shape of the basic components (so the fabrication process is more efficient). RhinoScript is still quite new to me. I started with the Honeycomb script that Andrew Kudless wrote few years ago. The code still needs to be more optimized and cleaned up. But, the code works nonetheless.

—-

Option Explicit
‘by Andrew Kudless | andrew@materialsystems.org | april, 2005
‘Edited by Howard Jiho Kim | kimjiho@gmail.com | March, 2008

Sub OrientObjTwoSurfaces()

Dim orientObj
Dim orientPoint(2)

Dim sourceSurf, sourceSurf2
Dim uDiv, vDiv, maxDiv
Dim uArray, vArray
Dim i,j, index

‘surface 1 variables
Dim uMax, vMax
Dim uInc, vInc
Dim uStart, vStart

‘surface 2 variables
Dim u2Max, v2Max
Dim u2Inc, v2Inc
Dim u2Start, v2Start

‘surface points variables
Dim arrParam(1), arr2Param(1), arrPoint, arr2Point
Dim surface1Points(), surface2Points()

‘Rhino.EnableRedraw vbFalse

orientObj = Rhino.GetObject (“Select the Object to Orient”)
If IsNull(orientObj) Then Exit Sub

orientPoint(0) = Rhino.GetPoint(“Select Point 1 to Orient”)
If IsNull(orientPoint(0)) Then Exit Sub
orientPoint(1) = Rhino.GetPoint(“Select Point 2 to Orient”)
If IsNull(orientPoint(1)) Then Exit Sub
orientPoint(2) = Rhino.GetPoint(“Select Point 3 to Orient”)
If IsNull(orientPoint(2)) Then Exit Sub

uDiv = Rhino.GetInteger (“Enter the number of divisions in the U direction”)
If IsNull(uDiv) Then Exit Sub

vDiv = Rhino.GetInteger (“Enter the number of divisions in the V direction”)
If IsNull(vDiv) Then Exit Sub

‘Get inputs
sourceSurf = Rhino.GetObject (“Select the base Surface”, 8)
If IsNull(sourceSurf) Then Exit Sub

‘Get inputs
sourceSurf2 = Rhino.GetObject (“Select a target Surface”, 8)
If IsNull(sourceSurf2) Then Exit Sub

ReDim uVal(uDiv)
ReDim vVal(vDiv)

ReDim u2Val(uDiv)
ReDim v2Val(vDiv)

uMax = Rhino.SurfaceDomain (sourceSurf, 0)
vMax = Rhino.SurfaceDomain (sourceSurf, 1)

uInc = uMax(1)/uDiv
vInc = vMax(1)/vDiv

For i = 0 To uDiv
uVal(i) = i * uInc
Rhino.Print “uVal(” & i & “):” & uVal(i)

Next

For i = 0 To vDiv
vVal(i) = i * vInc
Rhino.Print “vVal(” & i & “):” & vVal(i)
Next

u2Max = Rhino.SurfaceDomain (sourceSurf2, 0)
v2Max = Rhino.SurfaceDomain (sourceSurf2, 1)

u2Inc = u2Max(1)/uDiv
v2Inc = v2Max(1)/vDiv

For i = 0 To uDiv
u2Val(i) = i * u2Inc
Rhino.Print “u2Val(” & i & “):” & u2Val(i)
Next

For i = 0 To vDiv
v2Val(i) = i * v2Inc
Rhino.Print “v2Val(” & i & “):” & v2Val(i)
Next

Rhino.Print “Calculating Array…”

‘Find which direction has more points
If uDiv >= vDiv Then
maxDiv = uDiv
Else
maxDiv = vDiv
End If

‘ARRAY POINS on SURFACE1
Dim targetPoint(2)
Dim p1, arrVector, NewLine, NewLine2, line1, line2, line3, arrXform
Dim arrPlane, arrRotated

For i=0 To uDiv

For j=0 To vDiv
arrParam(0) = uVal(i)
arrParam(1) = vVal(j)
arrPoint = Rhino.EvaluateSurface(sourceSurf, arrParam)
line1 = Rhino.AddPoint(arrPoint)
targetPoint(0) = Rhino.PointCoordinates(line1)

arr2Param(0) = uVal(i)
arr2Param(1) = vVal(j)
arr2Point = Rhino.EvaluateSurface(sourceSurf2, arr2Param)
line2 = Rhino.AddPoint(arr2Point)
targetPoint(2) = Rhino.PointCoordinates(line2)

NewLine = Rhino.AddLine (arrPoint, arr2Point)

arrVector = Rhino.VectorCreate(arr2Point, arrPoint)
Rhino.ViewCPlane , Rhino.PlaneFromNormal(arrPoint, arrVector)

arrPlane = ViewCPlane
arrRotated = RotatePlane(arrPlane, 90, arrPlane(1))
Rhino.ViewCPlane , arrRotated

arrPlane = ViewCPlane

NewLine2 = Rhino.RotateObject(NewLine, arrPlane(0), 90.0, ,True)

arrPoint = Rhino.CurveEndPoint(NewLine2)
line3 = Rhino.AddPoint(arrPoint)
targetPoint(1) = Rhino.PointCoordinates(line3)

If IsArray(orientPoint) Then
If IsArray(targetPoint) Then
Rhino.OrientObject orientObj, orientPoint, targetPoint, 1
End If
End If

Rhino.DeleteObject (line1)
Rhino.DeleteObject (line2)
Rhino.DeleteObject (line3)
‘Rhino.DeleteObject (NewLine)
Rhino.DeleteObject (NewLine2)

Next
Next

‘Rhino.EnableRedraw vbTrue
End Sub

OrientObjTwoSurfaces
Rhino.Print “Array Complete”

Feb
20

Rhino Explicit History Surface Blend

I was looking at the youtube video of this surface blend uploaded by David Rutten: http://youtube.com/watch?v=u25zgxieIww

The updated version of the rhino explicit history has a new feature called “slider” which makes this quite easy. Take a look at these files:

http://crtl-i.com/blog/wp-content/uploads/2008/02/crtli_exhis_ex21.3dm

http://crtl-i.com/blog/wp-content/uploads/2008/02/crtli_exhis_ex2.wrm

Feb
11

Explicit history example files

These are the rhino files that perform the explicit history example shown below:

crtli_exhis_ex1.3dm
crtli_exhis_ex1.wrm

First open the rhino file, and then open the explicit history definition from the ExplicitHistory plug-in interface. Edit the surfaces included the rhino file, and you’ll see how Rhino can actually be parametric. Also note the angle parameter in the “Rot” node and the linear relationship described in the “F(x)” node.

Jan
27

Rhino Explicit History

A new plug-in for Rhino4 is being developed. Rhino is finally going (pseudo) parametric. It’s still at an early stage, but the potential it has is amazing. I’ve been exploring this new world of Rhino past few days. It’s like scripting without coding. Here’s an example of what it can do.

Nov
07

coordinates

If the tower you’re designing is super curvy and if none of your floor plates are shaped the same, it becomes really hard to transfer the geometry into construction. One of the most basic information that the builders need is coordinates from different areas of the building. The more organic the design, the more points you’ll have to provide them in order for the actual structure to come close to what you designed. aka. This can take forever.

So here’s a little script that will do this for you. This is actually the first rhinoscript I wrote :P  First it’ll ask you to choose a base point. The coordinates of the other points will be calculated using the base point as (0,0,0).

BasePointCoordinates

Sub CoordinatesBasePoint

Dim baseObject
baseObject = Rhino.GetPoint(“Select base point to be set as (0,0,0)”)
If IsNull(baseObject) Then Exit Sub

Dim arrObjects
arrObjects = Rhino.GetObjects(“Select points to calculate coordinates”, 1, True, True)
If Not IsArray(arrObjects) Then Exit Sub

Dim arrPoint0, arrVector, arrPoint3
arrPoint0 = Array(0,0,0)
arrVector = Rhino.VectorCreate(baseObject, arrPoint0)

Dim strObject, arrPoint, arrPoint2
For Each strObject In arrObjects
arrPoint = Rhino.PointCoordinates(strObject)
arrPoint2 = Rhino.PointSubtract(arrPoint, arrVector)
Rhino.AddTextDot Rhino.Pt2Str(arrPoint2, 3), arrPoint
Next

End Sub

CoordinatesBasePoint