////////////////////////////////////////////////////////////////// // hmCustomArray v0.1 - script file // Creation Date - 04.19.2009 // //Author: Horacio Mendoza //web: www.horaciomendoza.com //e-mail: hjmendoza@gmail.com // // Description: // Make an array of selected objects or just cubes(Defalut(no selection)) // You can add random scale and rotation to it and set distance between the objects. // Idea: you can use for testing rigidbodys or any simulation test :) //*************************************************************** // source and call the script with "hmCustomArray" //*************************************************************** /////////////////////////////////////////////////////////////////// global proc createArray() { int $limitX = `intField -query -value countX`; int $limitY = `intField -query -value countY`; int $limitZ = `intField -query -value countZ`; float $RNDscaleMin = `intField -query -value scaleRandMin`; float $RNDscaleMax = `intField -query -value scaleRandMax`; float $RNDrotationMin = `intField -query -value rotationRandMin`; float $RNDrotationMax = `intField -query -value rotationRandMax`; float $RNDscale; float $separationAverage =`intField -query -value separationAverage`; string $mySel[] = `ls -selection`; group -empty -name "cubeArray"; print `size ($mySel)`; if (size ($mySel) < 1){ polyCube -w 0.997 -h 0.997 -d 0.997; select pCube1; $mySel = `ls -selection`; } float $amount =0; progressWindow -title "Instancing in Progress" -progress $amount -status "Percentage Complete: 0%"; for ($i=0;$i<$limitX ;$i++){ for ($k=0;$k<$limitY;$k++){ for ($j=0;$j<$limitZ;$j++){ $amount++; if ($i == 0 || $i == $limitX-1 || $k == 0 || $k == $limitY-1 || $j == 0 || $j == $limitZ-1){ int $randObj = rand(0, `size($mySel)`); string $myInstance[] = `instance $mySel[$randObj]`; //Transform xform -absolute -t (($i-(($limitX-1)*.5))*(($separationAverage*0.05)+1)) (($j-(($limitY-1)*.5))*(($separationAverage*0.05)+1)) (($k-(($limitZ-1)*.5))*(($separationAverage*0.05)+1)) $myInstance; //Scale $RNDscale = rand(($RNDscaleMin*0.01),($RNDscaleMax*0.01)); xform -scale $RNDscale $RNDscale $RNDscale $myInstance; //Rotation $RNDrotation = (rand(($RNDrotationMin*0.01),($RNDrotationMax*0.01))*360); xform -rotation $RNDrotation $RNDrotation $RNDrotation $myInstance; parent $myInstance "cubeArray"; int $percent = ceil(($amount / (($limitX * $limitY * $limitZ)))*100); progressWindow -edit -progress $percent -status ("Percentage: " + $percent + "% (" + $amount + " out of " + ($limitX * $limitY * $limitZ) + ")"); } } } } delete $mySel; progressWindow -endProgress; } //////////////// // UI /////////////// /////////// global proc hmCustomArray() { string $window = "hmCustomArray"; if (`window -q -ex $window`) deleteUI $window; window -widthHeight 390 150 -title "hmCustomArray" -sizeable true $window; columnLayout -width 500 -height 150 -columnAlign "center"; rowLayout -numberOfColumns 6 -columnWidth6 60 60 60 60 60 60 -adjustableColumn 6 -columnAlign 1 "right" -columnAlign 3 "right" -columnAlign 5 "right" -columnAttach 1 "both" 0 -columnAttach 2 "both" 0 -columnAttach 3 "both" 0 -columnAttach 4 "both" 0 -columnAttach 5 "both" 0 -columnAttach 6 "both" 0; text -width 10 -label "Count X "; intField -width 20 -value 3 -minValue 2 countX;// text -width 10 -label "Count Y "; intField -width 20 -value 3 -minValue 2 countY;// text -width 10 -label "Count Z "; intField -width 60 -value 3 -minValue 2 countZ; // setParent..; rowLayout -numberOfColumns 4 -columnWidth4 115 60 115 60 -adjustableColumn 4 -columnAlign 1 "right" -columnAlign 3 "right" -columnAttach 1 "both" 0 -columnAttach 2 "both" 0 -columnAttach 3 "both" 0 -columnAttach 4 "both" 0; text -width 10 -label "Rotation Rand Min % "; intField -width 20 -value 100 -minValue 0 rotationRandMin;// text -width 10 -label "Rotation Rand Max % "; intField -width 60 -value 100 -minValue 0 rotationRandMax;// setParent..; rowLayout -numberOfColumns 4 -columnWidth4 115 60 115 60 -adjustableColumn 4 -columnAlign 1 "right" -columnAlign 3 "right" -columnAttach 1 "both" 0 -columnAttach 2 "both" 0 -columnAttach 3 "both" 0 -columnAttach 4 "both" 0; text -width 10 -label "Scale Rand Min % "; intField -width 20 -value 100 -minValue 0 scaleRandMin;// text -width 10 -label "Scale Rand Max % "; intField -width 60 -value 100 -minValue 0 scaleRandMax;// setParent..; rowLayout -numberOfColumns 2 -columnWidth2 170 60 -adjustableColumn 2 -columnAlign 1 "right" -columnAlign 2 "right" -columnAttach 1 "both" 0 -columnAttach 2 "both" 0; text -width 10 -label "Separation % "; intField -width 60 -value 0 -minValue 0 separationAverage;// setParent..; button -width 380 -height 35 -label "Create" -command "createArray()"; showWindow $window; } hmCustomArray;