/*-------------------------------- Updated 11-30-2008---- FBlocalTumble.mel - version 1.2 - by Chris "Funky Bunnies" Whitaker ======================================================== -Concept: A lot of modern software have 'smart tumbles' where it will tumble around whatever you have selected, We'd like to mimic it -What it does: Whenever you make a selection, it will rotate around the center of that selection. This works for objects or components Fixed Bugs:11-23-08: -Not all of menu would load correctly when disabled, cleaned code -Might give errors on some selection types, put catches in -------------------------------------------------------- Main proc: FBlocalTumble ========================================================= ========================================================================== // Please feel free to contact me with any suggestions or bugs \\ //----------------------------------------------------------------------\\ // Contact Me: Chris@FunkyBunnies3d.com \\ ========================================================================== ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Generic Disclaimer: Use at your own risk. I won't be responsible for anything bad that happens to your objects, scenes, or your car.// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */ //by the way, if you want this to run all the time, you can just open your usersetup.mel and add in a line with "FBlocalTumble" //or type this in and restart Maya (it'll type it in for you): /* { //This simply edits your usersetup.mel file to enable FBlocalTumble every session string $fileName = (`internalVar -userScriptDir` + "userSetup.mel"); int $userSetupId = `fopen $fileName "a"`; fprint $userSetupId ("\nFBlocalTumble(); \n"); fclose $userSetupId; } */ ////////////////////////////////////////////////////////////////////// //Proc name: FBlocalTumbleDoIt(int $onOff) // //takes: int $onOff // //returns: -none- // //Description: depending on $onOff, will tumble piv to 0,0,0 or // // center of the current selection of objects/components // ////////////////////////////////////////////////////////////////////// global proc FBlocalTumbleDoIt(int $onOff) {//just the proc to actually tumble based on selection string $currPanel = `getPanel -wf`; if ($onOff) //if on { if (size( `polyEvaluate -vc -ec -fc -uvc`) == 4 || size (`ls -sl -dag`) || size (`filterExpand -sm 0 -sm 9 -sm 10 -sm 11 -sm 12 -sm 22 -sm 23 -sm 24 -sm 28 -sm 30 -sm 31 -sm 32 -sm 34 -sm 35 -sm 36 -sm 37 -sm 38 -sm 39 -sm 40 -sm 41 -sm 42 -sm 43 -sm 44 -sm 45 -sm 46 -sm 47 -sm 49 -sm 50 -sm 51 -sm 68 -sm 70 -sm 72 -sm 73`)) // if there is any selection... { if (`size $currPanel` && `getPanel -typeOf $currPanel` == "modelPanel") { string $Cam = `modelPanel -q -cam $currPanel`; // getting panel with focus and current camera in one. float $bbox[3] = `exactWorldBoundingBox`; tumbleCtx -e -localTumble false tumbleContext; //set Tumble Pivot to the center of the exactWorldBoundingBox of selection setAttr ($Cam + ".tumblePivot") (($bbox[0] + $bbox[3])/2) (($bbox[1] + $bbox[4])/2) (($bbox[2] + $bbox[5])/2); } } } else { if (`size $currPanel` && `getPanel -typeOf $currPanel` == "modelPanel") { string $Cam = `modelPanel -q -cam $currPanel`; // getting panel with focus and current camera in one. tumbleCtx -e -localTumble false tumbleContext; //set Tumble Pivot to the center of the exactWorldBoundingBox of selection setAttr ($Cam + ".tumblePivot") 0 0 0; } } } ////////////////////////////////////////////////////////////////////// //Proc name: FBlocalTumbleTGL(int $onOff) // //takes: int $onOff // //returns: -none- // //Description: depending on $onOff, will turn on/off FBlocalTumble // ////////////////////////////////////////////////////////////////////// global proc FBlocalTumbleTGL(int $onOff) { if (!$onOff) //if sent 0 ("off") { print "FBlocalTumble Turned Off\n"; FBlocalTumbleDoIt(0); //reset pivot to 0 0 0 if (`optionVar -ex FBlocalTumble`) { int $FBlocalTumbleID = `optionVar -q FBlocalTumble`; if (`scriptJob -ex $FBlocalTumbleID`) { optionVar -remove FBlocalTumble; scriptJob -kill $FBlocalTumbleID; } } } else {//otherwise, make a new scriptjob and save it to optionVar print "FBlocalTumble Turned On\n"; optionVar -iv FBlocalTumble `scriptJob -cu 1 -e "SelectionChanged" "FBlocalTumbleDoIt(1);"`; FBlocalTumbleDoIt(1); } } ////////////////////////////////////////////////////////////////////// //Proc name: FBlocalTumble() // //takes: -none- // //returns: -none- // //Description: Main Proc that sets up menu and hotkeys // ////////////////////////////////////////////////////////////////////// global proc FBlocalTumble() { 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`; if (!stringArrayContains("FBlocalTumbleTGL", $FBmenuItems)) { setParent -m FBtoolsMenu; menuItem -divider 1; menuItem -ecr 0 -l "FBlocalTumble (disabled)" -ann "FBlocalTumble sets the camera Tumble pivot to the center of selection" -echoCommand false -c "if (`menuItem -q -l FBlocalTumbleTGL` == \"FBlocalTumble (disabled)\") { menuItem -e -l \"FBlocalTumble (enabled)\" FBlocalTumbleTGL; optionVar -iv FBlocalTumbleTgl 1; FBlocalTumbleTGL(1); } else {menuItem -e -l \"FBlocalTumble (disabled)\" FBlocalTumbleTGL; optionVar -iv FBlocalTumbleTgl 0; FBlocalTumbleTGL(0); }" FBlocalTumbleTGL; if (`optionVar -ex FBlocalTumbleTgl`) if (`optionVar -q FBlocalTumbleTgl`) //if == 1 { menuItem -e -l "FBlocalTumble (enabled)" FBlocalTumbleTGL; FBlocalTumbleTGL(1); } else //else 0 { menuItem -e -l "FBlocalTumble (disabled)" FBlocalTumbleTGL; FBlocalTumbleTGL(0); } } if (!stringArrayContains("FBlocalTumbleZero", $FBmenuItems)) { setParent -m FBtoolsMenu; menuItem -ecr 0 -l "Reset FBlocalTumble" -ann "resets camera tumble" -echoCommand false -c "FBlocalTumbleDoIt(0);" FBlocalTumbleZero; } if (!`runTimeCommand -exists FBlocalTumbleOff`) { runTimeCommand -cat "FBtools" -annotation "sets to default camera Tumble" -command "if (`menuItem -ex FBlocalTumbleTGL`) menuItem -e -l \"FBlocalTumble (disabled)\" FBlocalTumbleTGL; optionVar -iv FBlocalTumbleTgl 0; FBlocalTumbleTGL(0);" FBlocalTumbleOff; //make nameCommand nameCommand -annotation "sets to default camera Tumble" -command "FBlocalTumbleOff" FBlocalTumbleOffNameCommand; } if (!`runTimeCommand -exists FBlocalTumbleOn`) { runTimeCommand -cat "FBtools" -annotation "sets to FB local camera Tumble" -command "if (`optionVar -ex FBlocalTumbleTgl`)\r\n{ \r\n\tif (`optionVar -q FBlocalTumbleTgl`)//if variable = 1\r\n\t{ \r\n\t\tif (`menuItem -ex FBlocalTumbleTGL`) menuItem -e -l \"FBlocalTumble (disabled)\" FBlocalTumbleTGL; \r\n\t\toptionVar -iv FBlocalTumbleTgl 0; FBlocalTumbleTGL(0); \r\n\t} \r\n\telse\r\n\t{ \r\n\t\tif (`menuItem -ex FBlocalTumbleTGL`) menuItem -e -l \"FBlocalTumble (enabled)\" FBlocalTumbleTGL; \r\n\t\toptionVar -iv FBlocalTumbleTgl 1; FBlocalTumbleTGL(1); \r\n\t} \r\n}" FBlocalTumbleOn; //make nameCommand nameCommand -annotation "sets to FB local camera Tumble" -command "FBlocalTumbleOn" FBlocalTumbleOnNameCommand; } if (!`runTimeCommand -exists FBlocalTumbleTgl`) { runTimeCommand -cat "FBtools" -annotation "toggles FB local camera Tumble" -command ("if (`optionVar -ex FBlocalTumbleTgl`)\r\n{ \r\n\tif (`optionVar -q FBlocalTumbleTgl`)//if variable = 1\r\n\t{ \r\n\t\tif (`menuItem -ex FBlocalTumbleTGL`) menuItem -e -l \"FBlocalTumble (disabled)\" FBlocalTumbleTGL; \r\n\t\toptionVar -iv FBlocalTumbleTgl 0; FBlocalTumbleTGL(0); \r\n\t} \r\n\telse\r\n\t{ \r\n\t\tif (`menuItem -ex FBlocalTumbleTGL`) menuItem -e -l \"FBlocalTumble (enabled)\" FBlocalTumbleTGL; \r\n\t\toptionVar -iv FBlocalTumbleTgl 1; FBlocalTumbleTGL(1); \r\n\t} \r\n}\r\nelse\r\n{ \r\n\tif (`menuItem -ex FBlocalTumbleTGL`) menuItem -e -l \"FBlocalTumble (enabled)\" FBlocalTumbleTGL; \r\n\toptionVar -iv FBlocalTumbleTgl 1; FBlocalTumbleTGL(1); \r\n} ") FBlocalTumbleTgl; //make nameCommand nameCommand -annotation "toggles FB local camera Tumble" -command "FBlocalTumbleTgl" FBlocalTumbleTGLNameCommand; } } FBlocalTumble;