/*--------------------------------Updated 2-26-2012---- FBcombine (poly objects) by Chris "Funky Bunnies" Whitaker ======================================================= Main Procedure: FBcombine(); ======================================================== -Concept: Just a friendlier version of Maya's polygonal combine tool -How is it friendlier? -options to retain position, orientation, and/or parent of FIRST selected object -options to delete history afterward -options for a toggle to separate if FBcombine is run on one object -------------------------------------------------------- Change log: --2-26-2012 - fixed issue with options dialog not popping up properly... i dont recall this being a problem in maya 2009- but should be fixed now :) ========================================================*/ ////////////////////////////////////////////////////////////////////// //Proc name: FBcombineSetVars() // //Description: initializes variables to defaults // ////////////////////////////////////////////////////////////////////// global proc FBcombineSetVars() { optionVar -iv FBcombineTGL 1; optionVar -iv FBcombinePos 1; optionVar -iv FBcombineRot 1; optionVar -iv FBcombineParent 1; optionVar -iv FBcombineHist 1; } ////////////////////////////////////////////////////////////////////// //Proc name: FBcombineSave() // //Description: Saves optionVars from optionsGUI // ////////////////////////////////////////////////////////////////////// global proc FBcombineSave() {//save optionvars from FBcombine optionsGUI optionVar -iv FBcombineHist `radioButtonGrp -q -sl FBcombineHistRadio`; optionVar -iv FBcombineTGL `radioButtonGrp -q -sl FBcombineTglRadio`; optionVar -iv FBcombinePos `radioButtonGrp -q -sl FBcombinePosRadio`; optionVar -iv FBcombineRot `radioButtonGrp -q -sl FBcombineRotRadio`; optionVar -iv FBcombineParent `radioButtonGrp -q -sl FBcombineParentRadio`; } ////////////////////////////////////////////////////////////////////// //Proc name: FBcombineOptions() // //Description: Creates Options GUI for FBcombine // ////////////////////////////////////////////////////////////////////// global proc FBcombineOptions() { //optionvars for cleanup, toggle, and tolerance //remember these radiogroups use 1 instead of 0 if (!`optionVar -ex FBcombineTGL`) optionVar -iv FBcombineTGL 1; if (!`optionVar -ex FBcombinePos`) optionVar -iv FBcombinePos 1; if (!`optionVar -ex FBcombineRot`) optionVar -iv FBcombineRot 1; if (!`optionVar -ex FBcombineParent`) optionVar -iv FBcombineParent 1; if (!`optionVar -ex FBcombineHist`) optionVar -iv FBcombineHist 1; if (!`optionVar -ex FBcombineOff`) optionVar -iv FBcombineOff 0; if (`window -exists FBcombineOptions `) deleteUI FBcombineOptions; window -title "FBcombine Options" -wh 320 200 -menuBar on -mxb false FBcombineOptions; menu -label "Edit" -to 0 editmenu; menuItem -ecr 0 -label "Save Settings" -c "FBcombineSave"; menuItem -ecr 0 -label "Reset Settings" -c "FBcombineSetVars; FBcombineOptions;"; menuItem -ecr 0 -label "Add/Remove FBcombine" -c "if (`optionVar -q FBcombineInstall`==1) {optionVar -iv FBcombineInstall 2; deleteUI -mi FBcombine FBcombineOB; FBcombineUserSetup(0); warning \"FBcombine removed!\";} else {optionVar -iv FBcombineInstall 1; FBcombineUserSetup(1); FBcombineSetup; warning \"FBcombine added\";} "; menu -label "Help" -tearOff 0 helpmenu; menuItem -ecr 0 -label "About" -ann "About FBcombine" -c "FBcombineInfo();"; menuItem -divider 1; menuItem -ecr 0 -l "Contact Me" -ann "email: Chris@FunkyBunnies3d.com" -c "showHelp -absolute \"mailto: Chris@FunkyBunnies3d.com\""; menuItem -ecr 0 -label "Visit my website" -ann "www.FunkyBunnies3d.com" -c "showHelp -absolute \"http:\//www.FunkyBunnies3d.com\""; string $monkeys = `formLayout`; columnLayout -rs 4 ; radioButtonGrp -cat 1 "left" 14 -cw3 110 70 70 -label "Delete History:" -ann "delete construction history after FBcombine?" -sl `optionVar -q FBcombineHist` -numberOfRadioButtons 2 -labelArray2 "Enable" "Disable" FBcombineHistRadio; radioButtonGrp -cat 1 "left" 14 -cw3 110 70 70 -label "Toggle behavior: " -ann "set a behavior for FBcombine when only one object is selected" -sl `optionVar -q FBcombineTGL` -numberOfRadioButtons 2 -labelArray2 "Separate" "None" FBcombineTglRadio; separator -style none; radioButtonGrp -cat 1 "left" 14 -cw4 110 70 60 70 -label "Position:" -ann "snap pivot to first object's position, origin, or center" -sl `optionVar -q FBcombinePos` -numberOfRadioButtons 3 -labelArray3 "Retain" "Zero" "Center" FBcombinePosRadio; radioButtonGrp -cat 1 "left" 14 -cw3 110 70 70 -label "Rotation:" -ann "Setting to snap new object to first object's rotation" -sl `optionVar -q FBcombineRot` -numberOfRadioButtons 2 -labelArray2 "Retain" "Zero" FBcombineRotRadio; radioButtonGrp -cat 1 "left" 14 -cw3 110 70 70 -label "Parent:" -ann "Setting to parent new object under first object's parent" -sl `optionVar -q FBcombineParent` -numberOfRadioButtons 2 -labelArray2 "Retain" "Ignore" FBcombineParentRadio; setParent..; //setParent..; hmmmm this wasnt working in maya 2011+, maybe this is why? but why was it here in the first place O_O button -l "Apply" -ann "Apply settings and close window" -align "center" -w 105 -h 30 -c "FBcombineSave" Applybut; button -l "Cancel" -ann "Cancel operation" -align "center" -w 105 -h 30 -c "deleteUI FBcombineOptions" Cancelbut; formLayout -edit -attachNone Applybut "top" -attachForm Applybut "left" 4 -attachForm Applybut "bottom" 4 -attachPosition Applybut "right" 2 50 -attachNone Cancelbut "top" -attachPosition Cancelbut "left" 2 50 -attachForm Cancelbut "bottom" 4 -attachForm Cancelbut "right" 4 $monkeys; showWindow FBcombineOptions; } ////////////////////////////////////////////////////////////////////// //Proc name: FBcombineInfo() // //Description: Creates "About" window for FBcombine script // ////////////////////////////////////////////////////////////////////// global proc FBcombineInfo() { if (`window -ex FBcombineinfoWin`) deleteUI FBcombineinfoWin; if (`windowPref -q -ex FBcombineinfoWin`) windowPref -remove FBcombineinfoWin; window -rtf 1 -s 0 -tbm 0 -t "About FBcombine" FBcombineinfoWin; columnLayout -rs 5; frameLayout -bs "in" -li 60 -h 160 -w 236 -l "FB combine v.1.0" -mw 5; string $infoform = `formLayout`; text -l " Written by Chris \"Funky Bunnies\" Whitaker \n \n This script was created to simply bring more \noptions to the poly combine tool \nincludes: \n retaining original pivot position, rotation, and \n original parent based on first selected object, \n and separates if only one object is selected."; string $FBemail = `button -l "Chris@FunkyBunnies3d.com" -w 150 -al "center" -c "showHelp -absolute \"mailto:Chris@FunkyBunnies3d.com\""`; formLayout -e -af $FBemail "bottom" 10 -af $FBemail "left" 20 -af $FBemail "right" 20 $infoform; setParent..; setParent..; rowLayout -w 250 -cat 1 "left" 70 -cal 1 "center"; button -l "Close" -w 100 -al "center" -ann "Close window" -c "deleteUI FBcombineinfoWin;"; showWindow FBcombineinfoWin; } ////////////////////////////////////////////////////////////// //proc: FBcombineUserSetup() // //Desc: This adds or removes FBcombine from the userSetup // ////////////////////////////////////////////////////////////// global proc FBcombineUserSetup(int $addRemove) { //This simply edits your usersetup.mel file to enable FBsaveSelection every session string $fileName = (`internalVar -userScriptDir` + "userSetup.mel"); if ($addRemove) { int $userSetupId = `fopen $fileName "a"`; fprint $userSetupId ("\nFBcombine(); \n"); fclose $userSetupId; } else { //read to find unwanted line and store to $userSetupText[] int $userSetupId = `fopen $fileName "r"`; string $userSetupText[]; int $index = 0; while ( !`feof $userSetupId` ) { string $temp = `fgetline $userSetupId`; if (!endsWith($temp, "FBcombine(); \n")) $userSetupText[$index] = $temp; $index++; } fclose $userSetupId; //now write it from $userSetupText[] int $userSetupWriteId = `fopen $fileName "w"`; for ($i=0;$i<`size $userSetupText`;$i++) { fprint $userSetupWriteId $userSetupText[$i]; } fclose $userSetupWriteId; } } ////////////////////////////////////////////////////////////////////// //Proc name: FBcombineSetup() // //takes: -none- // //returns: -none- // //Description: Main Proc that does all the work and sets up menu // ////////////////////////////////////////////////////////////////////// global proc FBcombineSetup() { if (!`menu -q -ex FBtoolsMenu`) { menu -l "FB Tools" -p MayaWindow -to 1 -aob true FBtoolsMenu; setParent -m FBtoolsMenu; menuItem -ecr 0 -l "Contact Me" -ann "email: Chris@FunkyBunnies3d.com" -echoCommand true -c "showHelp -absolute \"mailto: Chris@FunkyBunnies3d.com\"" ContactItem; menuItem -ecr 0 -l "Visit my Website" -ann "www.FunkyBunnies3d.com" -echoCommand true -c "showHelp -absolute \"http:\//www.FunkyBunnies3d.com\"" WebsiteItem; } string $FBmenuItems[] = `menu -q -ia FBtoolsMenu`; //see if FBcombine already exists on here, if not create it if (!stringArrayContains("FBcombine", $FBmenuItems)) { setParent -m FBtoolsMenu; menuItem -divider 1; menuItem -ecr 0 -l "FBcombine" -ann "FBcombine (poly)" -echoCommand true -ddc "FBcombineOptions" -c "FBcombine" FBcombine; menuItem -l "FBsaveSelection Options" -ob 1 -c "FBcombineOptions" FBcombineOB; } } ////////////////////////////////////////////////////////////// //proc: FBcombine() // //Desc: This is the main proc that combines poly objects // // details at top of script... // ////////////////////////////////////////////////////////////// global proc FBcombine() { //optionvars for cleanup, toggle, and tolerance //remember these radiogroups use 1 instead of 0 if (!`optionVar -ex FBcombineTGL`) optionVar -iv FBcombineTGL 1; if (!`optionVar -ex FBcombinePos`) optionVar -iv FBcombinePos 1; if (!`optionVar -ex FBcombineRot`) optionVar -iv FBcombineRot 1; if (!`optionVar -ex FBcombineParent`) optionVar -iv FBcombineParent 1; if (!`optionVar -ex FBcombineHist`) optionVar -iv FBcombineHist 1; if (!`optionVar -ex FBcombineOff`) optionVar -iv FBcombineOff 0; string $selPolyObjs[] = `filterExpand -sm 12`;//first check to see if there are any poly objects selected if (!`optionVar -ex FBcombineInstall`) { FBcombineUserSetup(1); optionVar -iv FBcombineInstall 1; warning "FBcombine added to FBtools menu!"; } FBcombineSetup(); if (`size $selPolyObjs`<=1) { if (`optionVar -q FBcombineTGL` == 1 && `size $selPolyObjs`==1) { //if toggle is on, blahdeeblah... string $newObject[] = `polySeparate -ch 0 $selPolyObjs[0]`; //to delete the empty parent parent -w; delete $selPolyObjs[0]; } } else { //check for current parents of selected object so we can reparent the new object string $parent[] = `listRelatives -p $selPolyObjs[0]`; string $pivLocator[] = `spaceLocator -p 0 0 0 -n pivLocator`; parentConstraint -weight 1 $selPolyObjs[0] $pivLocator[0]; delete -constraints $pivLocator[0]; float $initPos[] = `xform -q -ws -rp $pivLocator[0]`; string $newObject[] = `polyUnite -ch 1 $selPolyObjs`; if (`optionVar -q FBcombinePos` == 1) xform -a -ws -piv $initPos[0] $initPos[1] $initPos[2] $newObject[0]; else if (`optionVar -q FBcombinePos` == 3) xform -cp $newObject[0]; parent $newObject[0] $pivLocator[0]; if (`optionVar -q FBcombineRot` == 1) makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $newObject[0]; if (`size $parent` && `objExists $parent[0]` && `optionVar -q FBcombineParent` == 1) parent $newObject[0] $parent[0]; else parent -w $newObject[0]; delete $pivLocator[0]; select -r $newObject[0]; //if delete history is set, delete the history... duh if (`optionVar -q FBcombineHist` == 1) delete -ch; } }FBcombine;