Option Explicit '------------------------------------------------------------------------------------------- 'this is a random walking program that may or may not put modules as it walks. It always keeps inside the module defined 'by the bounding box of the selected objects that define the repeated module. 'Pablo Miranda Carranza, code released under GNU General Public License (www.gnu.org/licenses/gpl.txt) '------------------------------------------------------------------------------------------- sub module_randomwalk Dim Arrayofobjects Dim mypos Dim bboxsize Dim xsize,ysize,zsize Dim i 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: 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 50 'copy them 50 times dice=rnd() 'throw the dice.... if dice<1/6 then 'if 1... mypos(0)=mypos(0)+xsize elseif dice<2/6 then 'if 2... mypos(0)=mypos(0)-xsize elseif dice<3/6 then 'if 3... mypos(1)=mypos(1)+ysize elseif dice<4/6 then '... mypos(1)=mypos(1)-ysize elseif dice<5/6 then mypos(2)=mypos(2)+zsize else mypos(1)=mypos(2)-zsize end if 'and with a provability to put a module or not: if(rnd<0.5) then Rhino.CopyObjects ArrayofObjects, Array(0,0,0), mypos 'check help for definition, needless to say... end if 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 module_randomwalk