Option Explicit '------------------------------------------------------------------------------------------- 'adding rectangular modules of variable size. The script first asks for a number of objects, it calculates 'their bounding box, and then it īsprincklesīthem around according to the sizes of the bounding box, so they are 'always aligned. 'Pablo Miranda Carranza, code released under GNU General Public License (www.gnu.org/licenses/gpl.txt) '------------------------------------------------------------------------------------------- sub random_place Dim Arrayofobjects Dim moveto Dim bboxsize Dim xsize,ysize,zsize Dim i Dim thebox randomize moveto=Array(0,0,0) 'this is just to tell Rhino that 'moveto' will be an array 'here we select an object: Arrayofobjects=Rhino.GetObjects("select objects") 'check RhinoScript For details of this Function 'and calculate the size of its bounding box, for which we have done a little function defined bellow bboxsize=calc_sizeofbox(Arrayofobjects) 'here we just copy the values returned, we don't need to (we could use directly bboxsize(0), bboxsize(1), bboxsize(2), 'but it is a bit clearer like this) xsize=bboxsize(0) ysize=bboxsize(1) zsize=bboxsize(2) For i=0 to 20 'copy them 50 times 'this here makes the whole trick... 'the int means that everything between parenthesis should be done in to an integer number (without fractions). 'we multiply it by 2 afterwards, which is the size (lenght, width and height of the box we will draw) moveto(0)=int(rnd()*3)*xsize moveto(1)=int(rnd()*3)*ysize moveto(2)=int(rnd()*3)*zsize Rhino.CopyObjects ArrayofObjects, Array(0,0,0), moveto 'check help for definition, needless to say... Next End Sub Function calc_sizeofbox(Arr_obs) Dim bbox Dim bsize' this is the array (point) we will use to store the size of the box, and that we will 'return' (send back from the function) bbox=Rhino.BoundingBox(Arr_obs) 'Rhino.BoundingBox returns an array of points with the vertices of the box. 'Check RhinoScript Help for details 'Rhino.AddBox bbox 'this is only for texting bounding boxes...comment off otherwise bsize=Array(0,0,0) 'here we calculate the distances between the vertices of the bounding box (width,length and height) 'check on the Rhino Help about BoundingBox, for seen which vertices are which, it is a drawing there bsize(0)=Rhino.Distance(bbox(0), bbox(1)) bsize(1)=Rhino.Distance(bbox(0), bbox(3)) bsize(2)=Rhino.Distance(bbox(0), bbox(4)) calc_sizeofbox=bsize 'return the result End Function random_place