/* This file downloaded from Highend3d.com '' '' Highend3d.com File Information: '' '' Script Name: abxPicker '' Author: '' Last Updated: Oct 02, 2006 '' Update/Change this file at: '' http://Highend3d.com/maya/downloads/mel_scripts/animation/4216.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. */ // Picker Maya Script // abxPicker.mel // // Version 1.0 // Created by J. Adam Burke adam@adamburke.net // Modified : 31 Sep 2006 // DESCRIPTION: // abxPicker provides artists, animators, and character TDs with an intuitive interface // for creating and using custom character control interfaces. Using drag and drop, you // can create, position, resize, and edit buttons to select character controls. // USAGE: // Source script and call "abxPicker;" // assign to shelf or hotkey as preferred // ©2006 J. Adam Burke // http://www.adamburke.net global proc abxPicker(){ if (`window -q -ex abxPickerWindow`){ showWindow abxPickerWindow; } else{ string $parent = `window -w 200 -h 300 -t abxPicker -tlb true abxPickerWindow`; $panelName = "abxPicker"; setParent $parent; $panelName = `formLayout -w 500 -h 500 $panelName`; //tabLayout -e -tabLabel $panelName "Picker" $parent; //--------------Toolbar Layout----------------------- rowLayout -nc 5 -adj 3 -co5 0 0 2 0 0 -cw5 23 23 67 23 23 -ct5 "both" "both" "both" "both" "both" -cl5 "center" "center" "right" "center" "center" abxPickerToolbar; iconTextButton -ann "New Picker Sheet" -image "fileNew.xpm" -w 23 -h 23 -command "layout -e -visible false abxPickerCharTabs;layout -e -visible true abxPickerNewForm"; iconTextButton -ann "Save Picker Sheet" -di "fileNew.xpm" -image "fileSave.xpm" -vis false -w 23 -h 23 -command "abxPickerWriteNode `tabLayout -q -st (eval(\"tabLayout -q -st abxPickerCharTabs\"))`;iconTextButton -e -vis false abxPickerSave;" abxPickerSave; textField -ann "Character Menu" -editable false -text "None" abxPickerCharText; popupMenu -b 1 abxPickerCharMenu; iconTextButton -ann "Redraw Picker Sheet" -image "autoload.xpm" -w 23 -h 23 -command "abxPickerRefresh"; iconTextButton -ann "Help" -style "iconOnly" -w 23 -h 23 -image "pickOtherComp.xpm" -label "?" -command "abxPickerHelp"; setParent..; //--------------Picker Tab Layout-------------------- tabLayout -tabsVisible false -imw 0 -imh 0 abxPickerCharTabs; abxPickerRefresh; setParent..; //--------------Bottom Toolbar Layout----------------- columnLayout -parent $panelName -w 400 -cal "center" -cat "both" 0 -adj true abxPickerColLyt; rowLayout -cw 1 17 -cw 2 17 -cw 3 17 -cw 4 17 -cw 5 20 -cw 6 20 -cw 7 20 -cw 8 20 -cw 9 20 -nc 9 -adj 8; iconTextButton -style "iconOnly" -ann "Drag and Drop: Red" -dtg "0:0:.7:.4:.4" -w 16 -h 16 -bgc .7 .4 .4 -dgc "abxPickerCtrlNew"; iconTextButton -style "iconOnly" -ann "Drag and Drop: Green" -dtg "0:0:.4:.7:.4" -w 16 -h 16 -bgc .4 .7 .4 -dgc "abxPickerCtrlNew"; iconTextButton -style "iconOnly" -ann "Drag and Drop: Blue" -dtg "0:0:.4:.5:.7" -w 16 -h 16 -bgc .4 .5 .7 -dgc "abxPickerCtrlNew"; iconTextButton -style "iconOnly" -ann "Drag and Drop: Yellow" -dtg "0:0:.7:.7:.4" -w 16 -h 16 -bgc .7 .7 .4 -dgc "abxPickerCtrlNew"; iconTextButton -style "textOnly" -ann "Command: Select Current" -label "Sl" -w 19 -h 16 -bgc .5 .5 .5 -dgc "abxPickerCtrlCommand" -c "/*select*/"; iconTextButton -style "textOnly" -ann "Command: Select Current and Translate" -label "T" -w 19 -h 16 -bgc .5 .5 .5 -dgc "abxPickerCtrlCommand" -c "/*selectT*/"; iconTextButton -style "textOnly" -ann "Command: Select Current and Rotate" -label "R" -w 19 -h 16 -bgc .5 .5 .5 -dgc "abxPickerCtrlCommand" -c "/*selectR*/"; iconTextButton -style "textOnly" -l "More..." -w 16 -h 16 -c "abxPickerBuildToolbox" ; iconTextButton -mw 0 -mh 0 -ann "Trash: Drag ctrls here to Delete" -style "iconOnly" -image "smallTrash.xpm" -w 20 -h 17 -dpc "abxPickerCtrlTrash"; setParent..; //--------------New Picker Layout ------------------- columnLayout -visible false -rs 2 -cat "both" 3 -adj true -parent $panelName abxPickerNewForm; textFieldGrp -adj 2 -cw 1 50 -label "Name" -text "Character" abxPickerCharNameTxt; textFieldGrp -adj 2 -cw 1 50 -label "SubSet" -text "Main" abxPickerSubNameTxt; textFieldButtonGrp -adj 2 -cw 1 50 -cw 3 30 -label "Image" -text "" -buttonLabel "B.." -bc "fileBrowserDialog -m 0 -fc \"abxPickerBrowsePath\" -an \"Choose Background Image\" -ds 0" abxPickerImagePath; colorSliderGrp -adj 3 -cw 1 50 -cw 2 30 -label "Color" -rgb .4 .4 .4 abxPickerBGColor; rowLayout -adj 1 -nc 3 -cw3 10 50 50 -ct3 "both" "both" "both" -cl3 "center" "center" "center" -co3 5 5 5; button -visible false; button -label "OK" -c "abxPickerNewSheet;layout -e -visible true abxPickerCharTabs;layout -e -visible false abxPickerNewForm" ; button -label "Cancel" -c "layout -e -visible true abxPickerCharTabs;layout -e -visible false abxPickerNewForm"; setParent..; text -al "center" -label "Tip: Leave \"Name\" field blank\n when using referencing with\n rename prefixes or namespaces"; formLayout -e -af abxPickerToolbar "top" 0 -af abxPickerToolbar "left" 0 -af abxPickerToolbar "right" 0 -aof abxPickerToolbar "bottom" -24 -af abxPickerCharTabs "top" 24 -af abxPickerCharTabs "left" 0 -af abxPickerCharTabs "right" 0 -ap abxPickerCharTabs "bottom" 18 100 -af abxPickerNewForm "top" 24 -af abxPickerNewForm "left" 0 -af abxPickerNewForm "right" 0 -ap abxPickerNewForm "bottom" 20 100 -aof abxPickerColLyt "top" -17 -af abxPickerColLyt "left" 1 -af abxPickerColLyt "right" 1 -ap abxPickerColLyt "bottom" 1 100 $panelName; // create script job to refresh picker window on scene loads string $listArray[] = `scriptJob -lj`; string $tokenBuffer[]; int $foundJob = 0; int $jobNum =0; for ($i=0;$i=$leftPos && $y>=$topPos && $x<=($leftPos+$width) && $y<=($topPos+$height)){ //print ($x+":"+$y+":::"+$leftPos+","+$topPos+","+($leftPos+$width)+","+($topPos+$height)+"\n"); //print ($uiName[$i]+"\n"); // flashes UI Color; //iconTextButton -e -bgc 1 1 1 $uiName[$i]; //iconTextButton -e -bgc $red $green $blue $uiName[$i]; return $uiName[$i]; } } return ""; } //------------------------------------------------------------------------ //sets the position of the button using attach position commands to the form layout global proc abxPickerSetPos(string $parent, string $control, int $x, int $y,int $width, int $height){ int $rightPos = ($x + $width)*-1; int $bottomPos = ($y + $height)*-1; int $parentWidth = `layout -q -w $parent`; int $parentHeight = `layout -q -h $parent`; formLayout -e -ap $control "left" $x 0 -ap $control "top" $y 0 -ap $control "right" $rightPos 0 -ap $control "bottom" $bottomPos 0 $parent; } //-------------------------------------------------------------------------- // creates a new button and encodes the position/color data into the label global proc string abxPickerNewButton(int $ctrlX, int $ctrlY, int $ctrlWidth, int $ctrlHeight, float $bgr, float $bgg, float $bgb, string $image,string $command, string $label){ // stores position and color data so it can be queried $data = ($ctrlX+":"+$ctrlY+":"+$bgr+":"+$bgg+":"+$bgb); string $newCtrl = `iconTextButton -mh 0 -mw 0 -style "iconAndTextVertical" -l $label -dtg $data -w $ctrlWidth -h $ctrlHeight -bgc $bgr $bgg $bgb -dgc "abxPickerCtrlDrag" -image $image -c $command`; return $newCtrl; } //------------------------------------------------------------------------- // shows the new form and creates a blank layout and node global proc abxPickerNewSheet () { global string $pickrPrefix; string $characterName = `textFieldGrp -q -text abxPickerCharNameTxt`; string $characterName2 = ""; if ($characterName != "") $characterName2 = ($characterName + "_"); string $subCharName = `textFieldGrp -q -text abxPickerSubNameTxt`; string $bgImage = `textFieldButtonGrp -q -text abxPickerImagePath`; float $bgColor[] = `colorSliderGrp -q -rgb abxPickerBGColor`; string $bgPic; if (!`tabLayout -q -ex ($characterName+"PkrLyt")`){ tabLayout -parent abxPickerCharTabs ($characterName+"PkrLyt"); //menuItem -parent "abxPickerCharMenu" -label $characterName -c ("tabLayout -e -st "+$characterName+"PkrLyt abxPickerCharTabs;textField -e -text "+$characterName+" abxPickerCharText"); } if ($characterName == "") formLayout -parent ($characterName+"PkrLyt") -dtg (" |"+$subCharName+"|"+$bgColor[0]+"|"+$bgColor[1]+"|"+$bgColor[1]) -bgc $bgColor[0] $bgColor[1] $bgColor[2] -dpc "abxPickerCtrlDrop" ($characterName2+$subCharName+"PkrLyt"); else formLayout -parent ($characterName+"PkrLyt") -dtg ($characterName2+"|"+$subCharName+"|"+$bgColor[0]+"|"+$bgColor[1]+"|"+$bgColor[1]) -bgc $bgColor[0] $bgColor[1] $bgColor[2] -dpc "abxPickerCtrlDrop" ($characterName2+$subCharName+"PkrLyt"); if (`filetest -f $bgImage`){ $bgPic = `symbolButton -enable false -image $bgImage -bgc $bgColor[0] $bgColor[1] $bgColor[2]`; //int $tmpWidth = `control -q -w $bgPic`; //int $tmpHeight = `control -q -h $bgPic`; //deleteUI -control $bgPic; //$bgPic = `iconTextButton -mh 0 -mw 0 -w $tmpWidth -h $tmpHeight -enable false -bgc $bgColor[0] $bgColor[1] $bgColor[2] -image $bgImage`; } else { $bgPic = `symbolButton -visible false -bgc $bgColor[0] $bgColor[1] $bgColor[2]`; } tabLayout -e -tabLabel ($characterName2+$subCharName+"PkrLyt") $subCharName ($characterName+"PkrLyt"); formLayout -e -af $bgPic "top" -2 -af $bgPic "left" -2 -an $bgPic "right" -an $bgPic "bottom" ($characterName2+$subCharName+"PkrLyt"); setParent ..; $pickrPrefix = ""; if ($characterName == ""){ abxPickerNewNode ($characterName2+$subCharName+"_PIKR") $bgImage ($bgColor[0]+":"+$bgColor[1]+":"+$bgColor[1]) 1 ; } else{ abxPickerNewNode ($characterName2+$subCharName+"_PIKR") $bgImage ($bgColor[0]+":"+$bgColor[1]+":"+$bgColor[1]) 0 ; } if ($characterName != "") menuItem -parent "abxPickerCharMenu" -label $characterName -c ("abxPickerMenuCmd \""+$characterName+"\""); else menuItem -parent "abxPickerCharMenu" -label "*Prefix*" -c ("abxPickerMenuCmd \""+$characterName+"\""); abxPickerMenuCmd $characterName; //textField -e -text $characterName abxPickerCharText; //tabLayout -e -st ($characterName2+$subCharName+"PkrLyt") ($characterName+"PkrLyt"); //tabLayout -e -st ($characterName+"PkrLyt") abxPickerCharTabs; } //------------------------------------------------------------------------- // deletes all current picker layouts and redraws them from the saved nodes global proc abxPickerRefresh () { string $pickerNodes[] = `ls "*_PIKR"`; string $loadedSheets[]; string $lastChar; string $charName; string $charName2; string $subName; string $tokenBuffer[]; $pickerNodes = stringArrayCatenate($pickerNodes,`ls "*:*_PIKR"`); if (`tabLayout -q -ex abxPickerCharTabs`){ $loadedSheets = `tabLayout -q -ca abxPickerCharTabs`; $lastChar = `textField -q -text abxPickerCharText`; } // hides all pickersheets, deletes picker sheets and character menu items. tabLayout -e -visible false abxPickerCharTabs; textField -e -text "None" abxPickerCharText; for ($each in $loadedSheets) deleteUI -layout $each; popupMenu -e -dai abxPickerCharMenu; if (size($pickerNodes) > 0){ setParent abxPickerCharTabs; for ($each in $pickerNodes){ $charName=""; tokenize $each ":" $tokenBuffer; if (size($tokenBuffer) < 2){ tokenize $each "_" $tokenBuffer; if (size($tokenBuffer) >= 3){ $charName = ($tokenBuffer[0]); for ($i=1;$i= 3){ $charName = ($tokenBuffer[0]); $charName2 = ($tokenBuffer[0]+"_"); for ($i=1;$i1) $pickrPrefix = ($charName+":"); else $pickrPrefix = $charName2; for ($i=0;$i<$count;$i++){ tokenize $data[$i] ":" $tokenBuffer; int $xPos = $tokenBuffer[0]; int $yPos = $tokenBuffer[1]; float $bgr = $tokenBuffer[2]; float $bgg = $tokenBuffer[3]; float $bgb = $tokenBuffer[4]; string $control; // if prefix flag is true if ($charPrefix == 1){ // if the data node has a rename prefix if ($charName2!=""){ // create the button that sets the pickrPrefix $control = `abxPickerNewButton $xPos $yPos $width[$i] $height[$i] $bgr $bgg $bgb $image[$i] ("global string $pickrPrefix=\""+$pickrPrefix+"\";"+$command[$i]) $label[$i]`; } else{ $control = `abxPickerNewButton $xPos $yPos $width[$i] $height[$i] $bgr $bgg $bgb $image[$i] ("global string $pickrPrefix=\"\";"+$command[$i]) $label[$i]`; } } else { $control = `abxPickerNewButton $xPos $yPos $width[$i] $height[$i] $bgr $bgg $bgb $image[$i] ("global string $pickrPrefix=\"\";"+$command[$i]) $label[$i]`; } abxPickerSetPos ($charName2+$subName+"PkrLyt") $control $xPos $yPos $width[$i] $height[$i]; } textField -e -text $charName abxPickerCharText; // formLayout -e -visible true ($charName2+$subName+"PkrLyt"); } //------------------------------------------------------------------ // writes the picker data to a transform node global proc abxPickerWriteNode (string $picker) { int $buttonCount = `layout -q -nch $picker`; string $uiName[] = `layout -q -ca $picker`; string $bgImage = `symbolButton -q -image $uiName[0]`; string $pickerData = `layout -q -dtg $picker`; string $data[]; int $width[]; int $height[]; string $overlay[]; string $image[]; string $command[]; string $label[]; string $nodeName = ""; for ($i=1;$i<$buttonCount;$i++){ $data[$i-1] = `iconTextButton -q -dtg $uiName[$i]`; $width[$i-1] = `control -q -width $uiName[$i]`; $height[$i-1] = `control -q -height $uiName[$i]`; $overlay[$i-1] = `iconTextButton -q -imageOverlayLabel $uiName[$i]`; $image[$i-1] = `iconTextButton -q -image1 $uiName[$i]`; $command[$i-1] = `iconTextButton -q -command $uiName[$i]`; $label[$i-1] = `iconTextButton -q -label $uiName[$i]`; } string $pickerDataBuffer[]; tokenize $pickerData "|" $pickerDataBuffer; if ($pickerDataBuffer[0] == " ") $nodeName = ($pickerDataBuffer[1]+"_PIKR"); else $nodeName = ($pickerDataBuffer[0]+$pickerDataBuffer[1]+"_PIKR"); if (!objExists($nodeName)) abxPickerNewNode ($nodeName) "" "" 0; print ("Saving "+$nodeName+"\n"); setAttr ($nodeName+".bgImage") -type "string" $bgImage; setAttr ($nodeName+".bgColor") -type "string" ($pickerDataBuffer[2]+":"+$pickerDataBuffer[3]+":"+$pickerDataBuffer[4]); setAttr ($nodeName+".count") ($buttonCount-1); int $charPrefix = `getAttr ($nodeName+".charPrefix")`; // build setAttr string $setAttrCmd = ("setAttr "+$nodeName+".data -type stringArray "+($buttonCount-1)); for ($each in $data) $setAttrCmd = ($setAttrCmd + " \"" + $each + "\""); eval ($setAttrCmd); string $setAttrCmd = ("setAttr "+$nodeName+".overlay -type stringArray "+($buttonCount-1)); for ($each in $overlay) $setAttrCmd = ($setAttrCmd + " \"" + $each + "\""); eval ($setAttrCmd); string $setAttrCmd = ("setAttr "+$nodeName+".image -type stringArray "+($buttonCount-1)); for ($each in $image) $setAttrCmd = ($setAttrCmd + " \"" + $each + "\""); eval ($setAttrCmd); // writes the command data, removes prefix code string $setAttrCmd = ("setAttr "+$nodeName+".command -type stringArray "+($buttonCount-1)); for ($each in $command) { //if ($charPrefix == 1){ string $tokenBuffer[]; tokenize $each ";" $tokenBuffer; string $newCommand = ""; $newCommand = $tokenBuffer[1]; for ($i=2;$i= 3){ $charName = ($tokenBuffer[0]); $charName2 = ($tokenBuffer[0]+"_"); for ($i=1;$i