' Written by Daniel Cardoso
' http://mit.edu/~dcardoso/www
' Oct 21 2008, updated March 10, 2009
'
' TODO : Implement multi-cutsheets
'
Call Main
Sub Main
Dim arrObjects, strObject
Dim boundingBox
Dim lstObj
Dim arrMP
Dim counter
Dim text
Dim width
Dim height
Dim currentX
Dim currentY
Dim xSize : xSize = Rhino.IntegerBox("Enter X dimension of cutsheet ", 100)
Dim ySize : ySize = Rhino.IntegerBox("Enter Y dimension of cutsheet ", 60 )
Dim xGap : xGap = Rhino.IntegerBox("Enter the desired space between pieces ", 2)
Dim yGap : yGap = Rhino.IntegerBox("Enter the desired space between pieces ", 5)
Dim thisBoundingBox
counter = 0
currentX = 0
currentY = 0
width = 5
Dim thisSrf
arrObjects = Rhino.GetObjects("Selecciona las superficies", 8)
If IsArray(arrObjects) Then
For Each strObject In arrObjects
Rhino.SelectObject(strobject)
Rhino.Command "UnrollSrf " & " Enter"
Rhino.UnSelectAllObjects()
lstObj = Rhino.FirstObject()
thisBoundingBox = Rhino.BoundingBox(lstObj)
Rhino.Print thisBoundingBox(1)(0)
width = thisBoundingBox(1)(0) - thisBoundingBox(0)(0)
height = thisBoundingBox(3)(1) - thisBoundingBox(0)(1)
Rhino.Print "Piece # " & counter & " size: " & width & ", " & height
If ( currentX > xSize-width ) Then
currentY = currentY + height + yGap
currentX = 0
End If
currentX = currentX + width + xGap
If IsArray(arrMP) Then
Rhino.Print "It is an array"
Rhino.AddPoint arrMP(0)
text = Rhino.AddText(counter, arrMP(0))
End If
Next
End If
End Sub
RandomNumber Function with Ranges and error catching
Function RandomNumber(nMin, nMax) ''Courtesy of McNeel
RandomNumber = Null
If Not IsNumeric(nMin) Then Exit Function
If Not IsNumeric(nMax) Then Exit Function
If nMin >= nMax Then Exit Function
Randomize
RandomNumber = Int((nMax - nMin + 1) * Rnd + nMin)
End Function
Create a grid of points on a surface via UV parameters
' Written by Daniel Cardoso Ll.
'
Function createGrid(divisions)
Dim superficiedomain, superficieUdomain, superficieVdomain
'how many divisions on surface
Dim surface : surface = Rhino.GetObject ("Enter Surface: ",8)
Dim i,j, point
Dim uDir, vDir
ReDim points(divisions, divisions)
Dim uDomain : uDomain = Rhino.surfacedomain (surface,0)
Dim vDomain : vDomain = Rhino.surfacedomain (surface,1)
Dim umin : umin = uDomain(0)
Dim umax : umax = uDomain(1)
Dim vmin : vmin = vDomain(0)
Dim vmax : vmax = vDomain(1)
'looping
For i = 0 To divisions
For j = 0 To divisions
'get parameter location in grid
uDir = (i * (umax - umin)/divisions) + umin
vDir = (j * (vmax - vmin)/divisions) + vmin
'get 3d location in scene using parameters
point = Rhino.evaluatesurface (surface, Array(uDir, vDir))
points(i,j) = point
'add 3d location to scene
Rhino.addpoint point
Next
Next
createGrid = points
End Function
Vector Field
' Based on David Rutten's code
Sub VectorField
Dim strCloudID
strCloudID = Rhino.GetObject("Input pointcloud", 2, True, True)
If IsNull(strCloudID) Then Exit Sub
Dim arrPoints : arrPoints = Rhino.PointCloudPoints(strCloudID)
Dim ptBase : ptBase = Array (10,10,10)
If IsNull(ptBase) Then Exit Sub
Dim i
For i = 0 To UBound(arrPoints)
Dim vecBase
vecBase = Rhino.VectorCreate(arrPoints(i), ptBase)
Dim vecDir : vecDir = Rhino.VectorCrossProduct(vecBase, Array(0,0,1))
If Not IsNull(vecDir) Then
vecDir = Rhino.VectorUnitize(vecDir)
vecDir = Rhino.VectorScale(vecDir, 2.0)
Call AddVector(vecDir, arrPoints(i))
End If
Next
End Sub
Function AddVector(ByVal vecDir, ByVal ptBase)
On Error Resume Next
AddVector = Null
If IsNull(ptBase) Or Not IsArray(ptBase) Then
ptBase = Array(0,0,0)
End If
Dim ptTip
ptTip = Rhino.PointAdd(ptBase, vecDir)
If Not (Err.Number= 0) Then Exit Function
AddVector = Rhino.AddLine(ptBase, ptTip)
If Not(Err.Number = 0) Then Exit Function
If IsNull(AddVector) Then Exit Function
Call Rhino.CurveArrows(AddVector, 2)
End Function
Random Point Cloud Generator (two functions)
'Written by Daniel Cardoso Ll.
'March 2009
Function generateRandomPointCloud(nOfPoints)
Dim i
ReDim points(nOfPoints)
For i = 0 To nOfPoints-1
Rhino.Print "Generating Point " & i
generateRandomPoint 0,400
'Rhino.Print Pt2Str(points(i))
Next
'generateRandomPointArray = Rhino.AddPointCloud(points)
generateRandomPointCloud = points
End Function