2d Grid [Boxes]

3b-grid-boxes

3a-grid-boxes1

Option Explicit
'Script written by <karthik.dondeti>
'Script copyrighted by <yet.another.script>
'Script version Monday, February 02, 2009 1:29:55 PM

Call Main()
Sub Main()

	'clear any existing debris
	Dim delObj:delObj = Rhino.AllObjects (True)
	If IsArray (delObj) Then
		Call Rhino.DeleteObjects (delObj)
	End If 

	'create box at origin
	Rhino.Command ("box c 0,0,0 1 1 1")
	Dim strBox:strBox = Rhino.FirstObject
	Dim n:n = 24
	'compute grid points
	Dim i,j,arrPts(),a
	Dim arrOrigin:arrOrigin = array(0,0,0)

	'copy boxes
	For j=0 To n
		For i=0 To n
			ReDim Preserve arrPts((n+1)*(n+1))
			arrPts(i+j*(n+1)) = array (i,j,0)
			Call Rhino.CopyObject (strBox, arrOrigin, arrPts(i+j*(n+1)))
		Next
	Next	

	'scale boxes random
	Dim k:k=0
	Dim m
	Dim strOneBox, strCentroid, arrScalePoint
	Dim strAllBoxes:strAllBoxes = Rhino.AllObjects

	For Each strOneBox In strAllBoxes
		strCentroid = rhino.SurfaceAreaCentroid (strOneBox)
		m =abs(cos(2*pi*k/4*n))+abs(sin(2*pi*k/n))
		arrScalePoint = Array (strCentroid(0)(0),strCentroid(0)(1),0)
		rhino.ScaleObject strOneBox, arrScalepoint, array (0.9,0.9,m)
		k=k+1
	Next

End Sub
Advertisements

~ by Karthik Dondeti on February 2, 2009.

One Response to “2d Grid [Boxes]”

  1. Hi, I have a problem with this script, when I load it, it deletes my polymesh I want to transform into boxes. What am I doing wrong?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: