/* This file downloaded from Highend3d.com '' '' Highend3d.com File Information: '' '' Script Name: morrissFold '' Author: morriss '' Last Updated: Jul 25, 2009 '' Update/Change this file at: '' http://Highend3d.com/maya/downloads/mel_scripts/animation/3222.html '' '' Please do not alter any information above this line '' it is generated dynamically by Highend3d.com and will '' be changed automatically on any updates. */ ////////////////////////////////////////////////////////////////// // morrissFold v0.1 //----------------------------------------- // written by : ozgun zumrut (aka morriss) // // www.ozgunzumrut.com // //----------------------------------------- // hi everybody , just type "morrissFold" to the command line and follow the instructions. // for examples , you can check my website. // // i think this is useful for some architectural guys :) // // feel free to use. //----------------------------------------------------------------- //////////////////////////////////////////////////////////////////// global proc morrissFold() { morrissFoldingWindow(); } global proc string getPrefix() { string $prefix = "mFoldGroup_"; return $prefix; } global proc string[] getObjects() { string $prefix = getPrefix(); string $objects[] = `ls -sl`; int $size = size($objects); if ($size<2) error "You have to choose two or more objects !!!"; for($i=0; $i<$size; $i++) { string $match = `match ("^"+$prefix) $objects[$i]`; if ($match == $prefix) error "One or more selected objects are in the FoldingGroup that already exists !!!"; } return $objects; } //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// global proc morrissFoldingWindow() { if(`window -ex morrissFoldingWindow`) deleteUI morrissFoldingWindow; window -t "morrissFold v 0.1" -s false morrissFoldingWindow; //layout columnLayout; string $createButton=`button -l "Create Folding Group" -w 200 -bgc .7 .8 1 -ann "Creates a new folding group." -command "morrissFoldingCreateGroup()"`; separator -w 200;separator -w 200; string $deleteButton=`button -l "Delete Folding Group" -w 200 -bgc 1 .7 .7 -ann "Deletes a folding group.(First, select any object from the group)" -command "morrissFoldingDeleteGroup()"`; separator -w 200;separator -w 200;separator -w 200; separator -w 200;separator -w 200;separator -w 200; separator -w 200;separator -w 200;separator -w 200; string $helpButton=`button -l "HELP !!!" -w 200 -bgc .7 1 .7 -ann "Duude !! , what the heck is this ??" -command "morrissFoldingHelpWindow()"`; showWindow morrissFoldingWindow; } //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// global proc morrissFoldingHelpWindow() { if(`window -ex morrissFoldingHelpWindow`) deleteUI morrissFoldingHelpWindow; window -t "morrissFoldingHelp" -s false morrissFoldingHelpWindow; columnLayout; separator -w 500; text -al "left" -w 500 -fn "boldLabelFont" -l "Create Folding Group :" -bgc .7 .8 1; separator -w 500; text -al "left" -w 500 -l "Creates a new folding group. First select some objects "; text -al "left" -w 500 -l "that in the same axis and has different center points."; text -al "left" -w 500 -l "Then push the button and enter the new folding group name."; text -al "left" -w 500 -l "(You can't select an object that already in a folding group)" -fn "boldLabelFont"; text -al "left" -w 500 -l "(if you want to change axis, first delete and re-create)" -fn "boldLabelFont"; text -al "left" -w 500 -l "Then select the folding axis."; separator -w 500; text -al "left" -w 500 -fn "boldLabelFont" -l "Delete Folding Group :" -bgc 1 .7 .7; separator -w 500; text -al "left" -w 500 -l "Deletes folding groups. Just select any objects from the groups."; showWindow morrissFoldingHelpWindow; } global proc string morrissFoldingAxisSelectionWindow() { string $axisDialog = `confirmDialog -t "axis" -m "which axis you want to fold" -b "x" -b "y" -b "z" -b "-x" -b "-y" -b "-z" -ds "dismiss"`; return $axisDialog; } global proc string[] morrissFoldingSort(string $objects[] ,int $axis ,int $negOrPos) { int $size = size($objects); string $sortedObjects[]; float $tempLow = -2000000000; int $sortCount=0; do { int $i; float $tempHigh = 2000000000; for($i=0 ; $i<$size ;$i++) { float $pos[] = morrissFoldingFindObjectsCenter($objects[$i]); float $value = $pos[$axis]; if ($value < $tempHigh && $value > $tempLow) { $tempHigh = $value; $sortedObjects[$sortCount] = $objects[$i]; } } $tempLow = $tempHigh; $sortCount++; }while ($sortCount<$size); if ($negOrPos) $sortedObjects = reverseOrderStringArray($sortedObjects); if (size($sortedObjects)<$size) error "There are some objects has same center point !!!"; return $sortedObjects; } global proc float[] morrissFoldingFindObjectsCenter(string $object) { // 0-xmin 1-ymin 2-zmin 3-xmax 4-ymax 5-zmax float $pos[]; float $bbCoords[] = `xform -q -a -ws -bb $object`; $pos[0] = ($bbCoords[0]+$bbCoords[3])/2; $pos[1] = ($bbCoords[1]+$bbCoords[4])/2; $pos[2] = ($bbCoords[2]+$bbCoords[5])/2; return $pos; } global proc string[] reverseOrderStringArray(string $array[]) { int $size = size($array); string $tempArray[] = $array; int $i; int $revi = $size-1; for ($i ; $i<$size ; $i++) { $array[$i] = $tempArray[$revi]; $revi--; } return $array; } global proc string[] morrissFoldingRenamer (string $objects[] , string $prefix , int $padding) { string $renamedObjects[]; int $i; for ($i = 0 ; $i < size($objects) ; $i++) { string $newname = $prefix + "_" + morrissFoldingPadding($padding , ($i+1)); rename $objects[$i] $newname; $renamedObjects[$i] = $newname; } return $renamedObjects; } global proc string morrissFoldingPadding (int $padding, string $number) { string $zero = "0"; while (size ($number) < $padding) { $number = $zero+$number; } return $number; } global proc string[] morrissFoldingFreezeMovePivot(string $objects[] , int $vector , int $minOrMax) { int $i; for ($i=0 ; $i