Option Explicit 'Script written by Russell Loveridge 'Script copyrighted by Call Main() ' This script show how to "NEST" two loops to create a 2d field of objects ' It adds on a third loop so that two objects are made at each gridpoint - but the two objects are different. Sub Main() 'declare our variables Dim strObject ' the identifyer of the current object Dim intUnitsX, intUnitsY ' the number of units along one side of the square field - Note this is an integer - you cannot make 1/2 of an object.... Dim dblAreaX, dblAreaY ' the user input size of the field Dim dblSizeX, dblSizeY, dblSizeZ ' the standard size of each object Dim dblScale Dim i,j,k ' counter variables for the loops Dim arrCorner(7)' this is the array that defines the corners of the boxes Dim arrCubesBig Dim arrSphereSmall 'Layer Setup_________________________________________________________________ Rhino.AddLayer "Default" Rhino.CurrentLayer "Default" ' This sets up a temorary holder layer to make sure that all TYPICAL layers can be deleted. Rhino.DeleteLayer("Layer 01") ' You can delete a layer with Rhinoscript ONLY if it is not current and if it contains NO objects. Rhino.DeleteLayer("Layer 02") Rhino.DeleteLayer("Layer 03") Rhino.DeleteLayer("Layer 04") Rhino.DeleteLayer("Layer 05") Rhino.AddLayer "L0", RGB(255, 0, 0) 'Make new layers - where we know the exact names" Rhino.AddLayer "L1", RGB(0, 255, 0) Rhino.CurrentLayer("L0") ' This makes the layer L0 current - any geometry we create with the layer current will be on this layer. Rhino.DeleteLayer("Default") ' Delete the temp layer. '_________________________________________________________________________ ' ask the user for the dimension of the side of the square field. dblAreaX = Rhino.GetReal("Input the Size of the field in the X direction", 120) If (VarType(dblAreaX) = vbNull Or (dblAreaX <= 0)) Then Exit Sub dblAreaY = Rhino.GetReal("Input the Size of the field in the Y direction", 120) If (VarType(dblAreaY) = vbNull Or (dblAreaY <= 0)) Then Exit Sub ' ask the user how many objects /side - NOTE: this must be an integer! intUnitsX = Rhino.Getinteger("How many units/row do you wish to have in X", 5) If (VarType(intUnitsX) = vbNull Or (intUnitsX <= 0)) Then Exit Sub intUnitsY = Rhino.Getinteger("How many units/row do you wish to have in X", 4) If (VarType(intUnitsY) = vbNull Or (intUnitsY <= 0)) Then Exit Sub ' calculate the size of the units on each axis... dblSizeX = (dblAreaX/intUnitsX) dblSizeY = (dblAreaY/intUnitsY) dblSizeZ = ((dblSizeX + dblSizeY)/2) ' a note to the command line to tell the user the size of each component. Rhino.print "Size in X and Y are = (" & dblSizeX & "," & dblSizeY & ")" For i = 1 To intUnitsX 'NOTE we are now limiting the numbers in X independantly For j = 1 To intUnitsY For k = 0 To 1 ' This is a BINARY loop - one option or the other toggeled for each grid point. If k=0 Then dblScale = 1.0 Rhino.CurrentLayer("L0") Else dblScale = 0.8 Rhino.CurrentLayer("L1") End If arrCorner(0) = Array(((i-1)*dblSizeX),((j-1)*dblSizeY),0) ' this is the first corner = lower left corner arrCorner(1) = Array((i*dblSizeX),((j-1)*dblSizeY),0) ' corner 2 arrCorner(2) = Array((i*dblSizeX),(j*dblSizeY),0) ' corner 3 arrCorner(3) = Array(((i-1)*dblSizeX),(j*dblSizeY),0) ' corner 4 - the last corner of the bottom level... arrCorner(4) = Array(((i-1)*dblSizeX),((j-1)*dblSizeY),dblSizeZ) 'this is the first corner on the top of the box arrCorner(5) = Array((i*dblSizeX),((j-1)*dblSizeY),dblSizeZ) 'top corner 2 arrCorner(6) = Array((i*dblSizeX),(j*dblSizeY),dblSizeZ) 'top corner 3 arrCorner(7) = Array(((i-1)*dblSizeX),(j*dblSizeY),dblSizeZ) 'last top corner strObject = Rhino.AddBox (arrCorner) Rhino.ScaleObject strObject, Array(((i-0.5)*dblSizeX),((j-0.5)*dblSizeY),0), array(dblScale,dblScale,1) Next Next Next arrCubesBig = Rhino.ObjectsByLayer("L0") arrSphereSmall = Rhino.ObjectsByLayer("L1") Rhino.BooleanDifference arrCubesBig, arrSphereSmall End Sub