💻 Rhino 5
🔼 Rhino Script
🛠️ Visual Basic
Developed to simulate the little bit of randomness which exists when you hand-make things and place them in the real world this tool simply shakes things up a little bit. Simply this rhinoscript uses a random function to produced minor variations in Position (move), Orientation (rotation), and Dimension (scale) within a range specified by the user.
Option Explicit
'Script written by <David Mans>
'Script copyrighted by <NeoArchaic Studio>
'Script version Tuesday, January 19, 2010 11:41:24 PM
Call Main()
Sub Main()
Dim arrInputs, arrTemp, intCount, arrSorting(), arrGroups
arrTemp = Rhino.GetObjects("Select Objects to Tile",, True)
If isNull(arrTemp) Then Exit Sub
arrGroups = SelectedGroups(arrTemp)
intCount = uBound(arrGroups)
ReDim arrSorting(intCount)
arrInputs = Rhino.PropertyListBox(array("Rotation Min", "Rotation Max", "Move", "Scale% Min", "Scale% Max"), array(0, 360, 0, 100, 100), "Jitter")
If isnull(arrinputs) Then Exit Sub
Dim i, cnPt
Call Rhino.EnableRedraw(False)
For i = 0 To intCount Step 1
arrSorting(i) = Rhino.ObjectsByGroup(arrGroups(i))
cnPt = boundingBoxCenterPoint(arrSorting(i))
Call Rhino.ScaleObjects(arrSorting(i), cnPt, array(random(arrInputs(3) * 0.01, arrInputs(4) * 0.01), random(arrInputs(3) * 0.01, arrInputs(4) * 0.01), random(arrInputs(3) * 0.01, arrInputs(4) * 0.01)), False)
Call Rhino.RotateObjects(arrSorting(i), cnPt, random(arrInputs(0), arrInputs(1)), Rhino.WorldXYPlane()(1), False)
Call Rhino.RotateObjects(arrSorting(i), cnPt, random(arrInputs(0), arrInputs(1)), Rhino.WorldXYPlane()(2), False)
Call Rhino.RotateObjects(arrSorting(i), cnPt, random(arrInputs(0), arrInputs(1)), Rhino.WorldXYPlane()(3), False)
Call Rhino.MoveObjects(arrSorting(i), cnPt, array(cnPt(0) + random(-1 * arrInputs(2), arrInputs(2)), cnPt(1) + random(-1 * arrInputs(2), arrInputs(2)), cnPt(2) + random(-1 * arrInputs(2), arrInputs(2))))
Next
Call Rhino.EnableRedraw(True)
End Sub
Function SelectedGroups(arrObjects)
SelectedGroups = Null
Dim arrGroups(), strGroup
Dim i, nCount, bAppend
nCount = -1
For i = 0 To UBound(arrObjects)
bAppend = False
strGroup = Rhino.ObjectTopGroup(arrObjects(i))
If Not IsNull(strGroup) Then
If (nCount = -1) Then
bAppend = True
ElseIf (FindGroup(strGroup, arrGroups) = -1) Then
bAppend = True
End If
If bAppend = True Then
nCount = nCount + 1
ReDim Preserve arrGroups(nCount)
arrGroups(nCount) = strGroup
End If
End If
Next
If (nCount > -1) Then SelectedGroups = arrGroups
End Function
Function FindGroup(strGroup, arrGroups)
Dim i
FindGroup = -1
For i = 0 To UBound(arrGroups)
If (StrComp(strGroup, arrGroups(i), 1) = 0) Then
FindGroup = i
Exit Function
End If
Next
End Function
Function boundingBoxCenterPoint(arrInputs)
boundingBoxCenterPoint = Null
Dim b,arrPt
b = Rhino.BoundingBox(arrInputs)
arrPt = array(b(0)(0) + (b(1)(0) - b(0)(0)) * 0.5, b(0)(1) + (b(3)(1) - b(0)(1)) * 0.5, b(0)(2) + (b(4)(2) - b(0)(2)) * 0.5)
boundingBoxCenterPoint = arrPt
End Function
Function random(min, max)
random = Null
Dim dblValue: dblValue = min + (max - min) * rnd()
random = dblValue
End Function
Comments