by Tuğrul Yazar | July 19, 2013 21:04
Recently, I returned to old fashion RhinoScripts in order to recapture its idea and functionalities again. After almost 10 years, this is my first experiment on creating a custom function that draws hexagonal grids. I tried to implement a fast process for it, however, there could be much faster ones. This script focuses on using functions, variables, and object arrays. I’ll continue to make more of these simple exercises and revisit some of the older studies on this blog page that were done with Grasshopper. So far, the initial experiment on a hexGrid function works properly. Below is the Rhinoscript code if you want to try it.
Option Explicit
Call Main()
Sub Main()
Dim testhex, testOrigin, testSize, testIter
testOrigin = Rhino.GetPoint("Center point of grid")
testSize = Rhino.GetReal("Grid size", 2, 0.1)
testIter = Rhino.GetInteger("Number of Iterations", 5, 1)
testhex = hexGrid(testOrigin, testSize, testIter)
' Rhino.SelectObject testhex(3, 5)
End Sub
Function hexGrid(ptOrigin, intSize, intIter)
'**************************************************************
' Purpose: Draw hexagonal grid
' Inputs : ptOrigin: Origin point of the grid
' intSize: Size of grid cells
' intIter: Number of iterations
' Returns: A 2-dimensional array of grid cells (polygons)
'**************************************************************
Dim hexReturn(100,100), hexOrigin, hexOrigin2, i, j, arrPly(100), arrHex(100)
hexOrigin = Rhino.MovePlane(Rhino.WorldXYPlane, ptOrigin)
hexReturn(0, 0) = Rhino.AddPolygon(hexOrigin, intSize, 6, True)
For i = 1 To intIter
arrPly(i) = Rhino.AddPolygon(hexOrigin, intSize * 1.5 * i, 6, False)
arrHex(i) = Rhino.DivideCurve(arrPly(i), i * 6, True, True)
Rhino.DeleteObject arrPly(i)
For j = 0 To (i * 6) - 1
hexOrigin2 = Rhino.MovePlane(Rhino.WorldXYPlane, arrHex(i)(j))
hexReturn(i, j) = Rhino.AddPolygon(hexOrigin2, intSize, 6, True)
Next
Next
hexGrid = hexReturn
End Function
Source URL: https://www.designcoding.net/revisiting-rhinoscript/
Copyright ©2024 designcoding unless otherwise noted.