Option Explicit '------------------------------------------------------------------------------------------- 'adding rectangular, different modules modules 'it defines and uses two functions: 'one for calculating the length, width and height of bounding boxes around objects --> calc_sizeofbox(Arr_obs) 'and the other for calculating the 'origin' of a bounding box --> calc_referencepoint(Arr_obs) 'Pablo Miranda Carranza, code released under GNU General Public License (www.gnu.org/licenses/gpl.txt) '------------------------------------------------------------------------------------------- sub module_combinatorial Dim Arrayofobjects1 Dim Arrayofobjects2 Dim mypos Dim bboxsize Dim xsize,ysize,zsize Dim origin1 'the origins of the bounding boxes Dim origin2 Dim i,j,k Dim thebox Dim dice randomize mypos=Array(0,0,0) 'this is just to tell Rhino that 'mypos' will be an array 'here we select an object: Arrayofobjects1=Rhino.GetObjects("select first set of objects") 'check RhinoScript For details of this Function Arrayofobjects2=Rhino.GetObjects("select second set of 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(Arrayofobjects1) 'here we just copy the values returned xsize=bboxsize(0) ysize=bboxsize(1) zsize=bboxsize(2) 'we repeate it here... bboxsize=calc_sizeofbox(Arrayofobjects2) 'and now we only copy them if they are bigger than the ones stored, so only the maximum of them, the 'biggest width, lenght or height will be stored... if bboxsize(0)>xsize then xsize=bboxsize(0) end if if bboxsize(1)>ysize then ysize=bboxsize(1) end if if bboxsize(2)>zsize then zsize=bboxsize(2) end if 'we calculate the respective origins of the bounding boxes for placing them... origin1=calc_referencepoint(Arrayofobjects1) origin2=calc_referencepoint(Arrayofobjects2) 'and here we place them For i=0 to 10 For j=0 to 10 'For k=0 to 1 dice=rnd() 'throw the dice.... 'there are two posibilities: 'either dice <1/2, so it copies array one 'or dice >1/2, so it copies array two 'one can add as many possibilities as one wants, of course if dice<1/2 then 'if 1... Rhino.CopyObjects ArrayofObjects1, origin1, Array(i*xsize,j*ysize,k*zsize) else Rhino.CopyObjects ArrayofObjects2, origin2, Array(i*xsize,j*ysize,k*zsize) end if 'Next Next 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, there 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 Function calc_referencepoint(Arr_obs) Dim bbox bbox=Rhino.BoundingBox(Arr_obs) 'Rhino.BoundingBox returns an array of points with the vertices of the box. 'Check RhinoScript Help for details calc_referencepoint=bbox(0) 'return the point with lowest x,y and z. look at the drawing in RhinoScript help for veryfing it... End Function module_combinatorial