/////////////////////////////////////////////////////////////////////////////////////////// // Script: mmListMelScripts.mel 1.0.3 // // Description: Generates a list of all mel-scripts spread over multiple folders, // // with options to eXecute, Source or Edit the files. // // A search function is included as well, for better overview over a // // large amount of scripts. // // Right-click on a script lists all global procs within the file with // // options to show additional information, such as return types and // // arguments. // // Right-click on one of the coloured buttons (X, E or S) will bring // // up additional options, such as "add to shelf", "duplicate file" and // // "copy file to...". // // Usage: Execute the following command, in order to run the script: // // mmListMelScripts(); // // Click on "Options". Define folders and path to external text editor. // //--------------------------------------------------------------------------------------- // // Author: Manuel Macha // // Homepage: http://www.manuelmacha.de/scripts/scripts.html // // Email: manuel@manuelmacha.de // /////////////////////////////////////////////////////////////////////////////////////////// global proc mmListMelScriptsRightClickCommand(int $buttonID1, int $buttonID2, int $commandID, int $destinationDir) { global string $gLastFocusedCommandExecuter; string $textFieldContent = `textField -query -text ("mmListMelScriptTextField" + $buttonID1 + "_" + $buttonID2)`; string $scriptPath = `frameLayout -query -label ("mmListMelScriptsFrameLayout" + $buttonID1)`; string $filter = `textField -query -text mmListMelScriptsTextFieldFilter`; string $melDirectories[] = `optionVar -query "melScriptDir"`; string $melDirectoriesParts[]; string $melScriptNames[] =`getFileList -folder ($melDirectories[$buttonID1] + "\\") -filespec ("*" + $filter + "*.mel")`; string $directory = ($melDirectories[$buttonID1] + "\\"); string $directoryParts[]; int $numDirectoryParts = `tokenize $directory "\\" $directoryParts`; string $buffer = ""; string $systemCommand; int $fileNumber = 1; for ($m = 0; $m < $numDirectoryParts; $m++) { if ($m == 0) { $buffer = $directoryParts[0]; } else { $buffer = ($buffer + "\\\\" + $directoryParts[$m]); } if ($m == ($numDirectoryParts - 1)) { $buffer = ($buffer + "\\\\"); } } $script = ($buffer + $melScriptNames[$buttonID2]); string $scriptName[]; tokenize $melScriptNames[$buttonID2] "." $scriptName; if ($commandID == 0) { textToShelf $textFieldContent $textFieldContent; } if ($commandID == 1) { textToShelf $textFieldContent ("source \"" + $script + "\";"); } if ($commandID == 2) { textToShelf $textFieldContent ("source \"" + $script + "\"; " + $textFieldContent + ";"); } if ($commandID == 3) { if (!`file -query -exists ($melDirectories[$buttonID1] + "\\" + $scriptName[0] + "_Copy1" + ".mel")`) { $systemCommand = ("(copy \"" + $melDirectories[$buttonID1] + "\\" + $melScriptNames[$buttonID2] + "\" \"" + $melDirectories[$buttonID1] + "\\" + $scriptName[0] + "_Copy1" + ".mel\")"); system $systemCommand; print ("// Result: " + $scriptName[0] + "_Copy1" + ".mel\n") ; } else { while (`file -query -exists ($melDirectories[$buttonID1] + "\\" + $scriptName[0] + "_Copy" + $fileNumber + ".mel")`) { $fileNumber++; } $systemCommand = ("(copy \"" + $melDirectories[$buttonID1] + "\\" + $melScriptNames[$buttonID2] + "\" \"" + $melDirectories[$buttonID1] + "\\" + $scriptName[0] + "_Copy" + $fileNumber + ".mel\")"); system $systemCommand; print ("// Result: " + $scriptName[0] + "_Copy" + $fileNumber + ".mel\n") ; } deleteUI mmListMelScriptsUI; mmListMelScripts; } if ($commandID == 4) { if (!`file -query -exists ($melDirectories[$destinationDir] + "\\" + $scriptName[0] + ".mel")`) { $systemCommand = ("(copy \"" + $melDirectories[$buttonID1] + "\\" + $melScriptNames[$buttonID2] + "\" \"" + $melDirectories[$destinationDir] + "\\" + $scriptName[0] + ".mel\")"); system $systemCommand; print ("// Result: " + $melDirectories[$destinationDir] + "\\" + $scriptName[0] + ".mel\n") ; } else { while (`file -query -exists ($melDirectories[$destinationDir] + "\\" + $scriptName[0] + $fileNumber + ".mel")`) { $fileNumber++; } $systemCommand = ("(copy \"" + $melDirectories[$buttonID1] + "\\" + $melScriptNames[$buttonID2] + "\" \"" + $melDirectories[$destinationDir] + "\\" + $scriptName[0] + "_Copy" + $fileNumber + ".mel\")"); system $systemCommand; print ("// Result: " + $melDirectories[$destinationDir] + "\\" + $scriptName[0] + "_Copy" + $fileNumber + ".mel\n") ; } deleteUI mmListMelScriptsUI; mmListMelScripts; } string $file = $script; int $fileId = `fopen $file "r"`; string $nextLine = `fgetline $fileId`; string $fileContent = $nextLine; if ($commandID == 5) { while (`size($nextLine)` > 0 ) { $nextLine = `fgetline $fileId`; $fileContent = ($fileContent + $nextLine); } fclose $fileId; textToShelf $textFieldContent $fileContent; } if ($commandID == 6) { system("\"explorer " + $melDirectories[$buttonID1] + "\""); } if ($commandID == 7) { while (`size($nextLine)` > 0 ) { $nextLine = `fgetline $fileId`; $fileContent = ($fileContent + $nextLine); } fclose $fileId; handleScriptEditorAction "clearHistory"; print $fileContent; } string $currentScriptEditor; if ($commandID == 8) { while (`size($nextLine)` > 0 ) { $nextLine = `fgetline $fileId`; $fileContent = ($fileContent + $nextLine); } fclose $fileId; $currentScriptEditor = $gLastFocusedCommandExecuter; cmdScrollFieldExecuter -edit -text $fileContent $currentScriptEditor; } } //substitute "_Copy1" "mmAlignControl_Copy1.mel" "" /////////////////////////////////////////////////////////////////////////////////////////// global proc mmListMelScriptsPostMenuOptionCommand(int $i, int $k, int $l) { string $button[] = {"X", "S", "E"}; string $command; string $parent = ("mmListMelScriptsUI"+ "|mmListMelScriptsScrollLayout1" + "|mmListMelScriptsColumnLayout1" + "|mmListMelScriptsFrameLayout" + $i + "|mmListMelScriptsSubColumnLayout" + $i + "|mmListMelScriptsSubRowLayout" + $i + "_" + $k + "|mmListMelScriptButton" + $button[$l] + "_" + $i + "_" + $k + "|mmListMelScriptOptionMenu" + $button[$l] + "_" + $i); string $filter = `textField -query -text mmListMelScriptsTextFieldFilter`; string $melDirectories[] = `optionVar -query "melScriptDir"`; string $melDirectoriesParts[]; string $melScriptNames[] =`getFileList -folder ($melDirectories[$i] + "\\") -filespec ("*" + $filter + "*.mel")`; string $directory = ($melDirectories[$i] + "\\"); string $directoryParts[]; int $numDirectoryParts = `tokenize $directory "\\" $directoryParts`; string $buffer = ""; for ($m = 0; $m < $numDirectoryParts; $m++) { if ($m == 0) { $buffer = $directoryParts[0]; } else { $buffer = ($buffer + "\\" + $directoryParts[$m]); } if ($m == ($numDirectoryParts - 1)) { $buffer = ($buffer + "\\"); } } $script = ($buffer + $melScriptNames[$k]); /////////////////////////////////////////////////////////////////////////////////////////// $command = ""; menuItem -parent $parent -label $melScriptNames[$k] -boldFont true; menuItem -parent $parent -divider true; $command = ("mmExecuteMel(" + $i + ", " + $k + ")"); menuItem -parent $parent -label "eXecute" -command $command; $command = ("mmSourceMel(" + $i + ", " + $k + ")"); menuItem -parent $parent -label "Source" -command $command; $command = ("mmEditMel(" + $i + ", " + $k + ")"); menuItem -parent $parent -label "Edit" -command $command; $command = ""; menuItem -parent $parent -divider true; setParent ..; $command = ("mmListMelScriptsRightClickCommand(" + $i + ", " + $k + ", 3, 0)"); menuItem -parent $parent -label "Duplicate file" -command $command; if (`size($melDirectories)` > 1) { menuItem -parent $parent -label "Copy file to..." -subMenu true -command $command; for ($n = 0; $n < `size($melDirectories)`; $n++) { if ($i != $n) { $command = ("mmListMelScriptsRightClickCommand(" + $i + ", " + $k + ", 4, " + $n + ")"); menuItem -label $melDirectories[$n] -command $command; } } setParent ..; } $command = ("mmListMelScriptsRightClickCommand(" + $i + ", " + $k + ", 6, 0)"); menuItem -parent $parent -label "Open Folder" -command $command; menuItem -parent $parent -divider true; menuItem -parent $parent -label "Add to shelf..." -subMenu true; $command = ("mmListMelScriptsRightClickCommand(" + $i + ", " + $k + ", 0, 0)"); menuItem -label "proc from textField;" -command $command; $command = ("mmListMelScriptsRightClickCommand(" + $i + ", " + $k + ", 1, 0)"); menuItem -label "source script;" -command $command; $command = ("mmListMelScriptsRightClickCommand(" + $i + ", " + $k + ", 2, 0)"); menuItem -label "source script; proc from textField;" -command $command; $command = ("mmListMelScriptsRightClickCommand(" + $i + ", " + $k + ", 5, 0)"); menuItem -label "entire script from file" -command $command; setParent ..; menuItem -parent $parent -label "Print to Script Editor..." -subMenu true; $command = ("mmListMelScriptsRightClickCommand(" + $i + ", " + $k + ", 7, 0)"); menuItem -label "to \"History\"" -command $command; $command = ("mmListMelScriptsRightClickCommand(" + $i + ", " + $k + ", 8, 0)"); menuItem -label "to \"Input\"" -command $command; } /////////////////////////////////////////////////////////////////////////////////////////// global proc mmChangeTextField(int $buttonID1, int $buttonID2) { string $userProc = `textField -query -text ("mmListMelScriptTextField" + $buttonID1 + "_" + $buttonID2)`; string $procNameParts[]; tokenize $userProc "()" $procNameParts; string $procTest = `whatIs $procNameParts[0]`; string $filter = `textField -query -text mmListMelScriptsTextFieldFilter`; string $melDirectories[] = `optionVar -query "melScriptDir"`; string $melScriptNames[] =`getFileList -folder ($melDirectories[$buttonID1] + "\\") -filespec ("*" + $filter + "*.mel")`; string $melScriptNamesParts[]; tokenize $melScriptNames[$buttonID2] "." $melScriptNamesParts; if ($melScriptNamesParts[0] != $procNameParts[0]) { textField -edit -font "boldLabelFont" ("mmListMelScriptTextField" + $buttonID1 + "_" + $buttonID2); } else { textField -edit -font "plainLabelFont" ("mmListMelScriptTextField" + $buttonID1 + "_" + $buttonID2); } } /////////////////////////////////////////////////////////////////////////////////////////// global proc mmListMelScriptsPostMenuCommand(int $i, int $k) { int $rightClickOption[] = `optionVar -query "rightClickOptions"`; string $script; string $filter = `textField -query -text mmListMelScriptsTextFieldFilter`; string $melDirectories[] = `optionVar -query "melScriptDir"`; string $melDirectoriesParts[]; string $melScriptNames[] =`getFileList -folder ($melDirectories[$i] + "\\") -filespec ("*" + $filter + "*.mel")`; string $directory = ($melDirectories[$i] + "\\"); string $directoryParts[]; int $numDirectoryParts = `tokenize $directory "\\" $directoryParts`; string $buffer = ""; for ($m = 0; $m < $numDirectoryParts; $m++) { if ($m == 0) { $buffer = $directoryParts[0]; } else { $buffer = ($buffer + "\\" + $directoryParts[$m]); } if ($m == ($numDirectoryParts - 1)) { $buffer = ($buffer + "\\"); } } $script = ($buffer + $melScriptNames[$k]); string $scriptNameParts[]; tokenize $melScriptNames[$k] "." $scriptNameParts; string $mainProcName = $scriptNameParts[0]; int $procNo = 0; string $procNames[]; string $file = $script; $fileId=`fopen $file "r"`; string $nextLine = `fgetline $fileId`; string $returnValue[]; //S// define variables to query argument list // string $myProc; string $varType[]; string $varName[]; string $procParts[]; string $vars[]; string $noBracket[]; string $procVars[]; string $firstPart[]; int $noOfVars; clear $varType; clear $varName; clear $procParts; clear $vars; clear $noBracket; clear $firstPart; //E// while (`size($nextLine)` > 0 ) { string $lineParts[] = stringToStringArray( $nextLine, " ()" ); if ($lineParts[0] == "global" && $lineParts[1] == "proc") { //S// query argument list // $myProc = $nextLine; $procParts = stringToStringArray( $myProc, "$" ); $noOfVars = size($procParts); if ($noOfVars > 1) { $firstPart = stringToStringArray( $procParts[0], "(" ); $varType[0] = $firstPart[1]; for ($g = 1; $g < $noOfVars; $g++) { clear $vars; $vars = stringToStringArray( $procParts[$g], "," ); $varName[$g - 1] = `substitute " " $vars[0] ""`; tokenize $varName[$g - 1] ")" $noBracket; $varName[$g - 1] = $noBracket[0]; $varType[$g] = `substitute " " $vars[1] ""`; } for ($h = 0; $h < ($noOfVars - 1); $h++) { if ($h == ($noOfVars - 2)) { $procVars[$procNo] = ($procVars[$procNo] + $varType[$h] + "$" + $varName[$h]); } else { $procVars[$procNo] = ($procVars[$procNo] + $varType[$h] + "$" + $varName[$h] + ", "); } } // print ($procVars[$procNo] + "\n"); } //E// string $proc = $lineParts[2]; if ( $proc == "string" || $proc == "float" || $proc == "int" || $proc == "string[]" || $proc == "float[]" || $proc == "int[]") { $returnValue[$procNo] = $proc; $proc = $lineParts[3]; } $procNames[$procNo] = $proc; $procNo++; } $nextLine = `fgetline $fileId`; } fclose $fileId; int $noOfProcs = size($procNames); string $userInterfaceItem = ("mmListMelScriptsUI"+ "|mmListMelScriptsScrollLayout1" + "|mmListMelScriptsColumnLayout1" + "|mmListMelScriptsFrameLayout" + $i + "|mmListMelScriptsSubColumnLayout" + $i + "|mmListMelScriptsSubRowLayout" + $i + "_" + $k + "|mmListMelScriptTextField" + $i + "_" + $k + "|mmListMelScriptPopupMenu" + $i); string $command; $command = ("textField -edit -font \"plainLabelFont\" -text \"" + $mainProcName + "()\" mmListMelScriptTextField" + $i + "_" + $k); menuItem -parent $userInterfaceItem -label $melScriptNames[$k] -boldFont true -command $command; menuItem -parent $userInterfaceItem -divider true; string $label; string $arguments[]; int $sizeArguments; string $argumentParts[]; if ($noOfProcs == 0) { menuItem -parent $userInterfaceItem -label "no procedures found!"; } else { for ($n = 0; $n < $noOfProcs; $n++) { $arguments = stringToStringArray( $procVars[$n], "," ); $sizeArguments = size($arguments); for ($p = 0; $p < $sizeArguments; $p++) { tokenize $arguments[$p] " " $argumentParts; $arguments[$p] = ($argumentParts[0] + " " + $argumentParts[1]); clear $argumentParts; } if ($procNames[$n] == $mainProcName) { $command = ("textField -edit -font \"plainLabelFont\" -text \"" + $procNames[$n] + "()\" mmListMelScriptTextField" + $i + "_" + $k); } else { $command = ("textField -edit -font \"boldLabelFont\" -text \"" + $procNames[$n] + "()\" mmListMelScriptTextField" + $i + "_" + $k); } if ($procNames[$n] == $mainProcName) { if ( $returnValue[$n] == "string" || $returnValue[$n] == "float" || $returnValue[$n] == "int" || $returnValue[$n] == "string[]" || $returnValue[$n] == "float[]" || $returnValue[$n] == "int[]") { if ($rightClickOption[0] == 1 && $rightClickOption[1] == 1) { $label = ("-> " + $procNames[$n] + "(" + $procVars[$n] + ") returnType: " + $returnValue[$n]); } if ($rightClickOption[0] == 0 && $rightClickOption[1] == 1) { $label = ("-> " + $procNames[$n] + "(" + $procVars[$n] + ")"); } if ($rightClickOption[0] == 1 && $rightClickOption[1] == 0) { $label = ("-> " + $procNames[$n] + "() returnType: " + $returnValue[$n]); } if ($rightClickOption[0] == 0 && $rightClickOption[1] == 0) { $label = ("-> " + $procNames[$n] + "()"); } if ($rightClickOption[2] == 1) { menuItem -parent $userInterfaceItem -label $label -subMenu true -command $command; menuItem -label ($procNames[$n] + "()") -command $command; menuItem -divider true -command $command; menuItem -label "return type:" -boldFont true -command $command; menuItem -label $returnValue[$n]; if ($procVars[$n] != "") { menuItem -divider true -command $command; menuItem -label "argument(s):" -boldFont true -command $command; for ($j = 0; $j < $sizeArguments; $j++) { menuItem -label $arguments[$j] -command $command; } } setParent ..; } else { menuItem -parent $userInterfaceItem -label $label -command $command; } } else { if ($rightClickOption[1] == 1) { $label = ("-> " + $procNames[$n] + "(" + $procVars[$n] + ")"); } else { $label = ("-> " + $procNames[$n] + "()"); } if ($rightClickOption[2] == 1) { if ($procVars[$n] != "") { menuItem -parent $userInterfaceItem -label $label -subMenu true -command $command; menuItem -label ($procNames[$n] + "()") -command $command; menuItem -divider true -command $command; menuItem -label "argument(s):" -boldFont true -command $command; for ($j = 0; $j < $sizeArguments; $j++) { menuItem -label $arguments[$j] -command $command; } } else { menuItem -parent $userInterfaceItem -label $label -command $command; } } } } else { if ( $returnValue[$n] == "string" || $returnValue[$n] == "float" || $returnValue[$n] == "int" || $returnValue[$n] == "string[]" || $returnValue[$n] == "float[]" || $returnValue[$n] == "int[]") { if ($rightClickOption[0] == 1 && $rightClickOption[1] == 1) { $label = ($procNames[$n] + "(" + $procVars[$n] + ") returnType: " + $returnValue[$n]); } if ($rightClickOption[0] == 0 && $rightClickOption[1] == 1) { $label = ($procNames[$n] + "(" + $procVars[$n] + ")"); } if ($rightClickOption[0] == 1 && $rightClickOption[1] == 0) { $label = ($procNames[$n] + "() returnType: " + $returnValue[$n]); } if ($rightClickOption[0] == 0 && $rightClickOption[1] == 0) { $label = ($procNames[$n] + "()"); } if ($rightClickOption[2] == 1) { menuItem -parent $userInterfaceItem -label $label -subMenu true -command $command; menuItem -label ($procNames[$n] + "()") -command $command; menuItem -divider true -command $command; menuItem -label "return type:" -boldFont true -command $command; menuItem -label $returnValue[$n]; if ($procVars[$n] != "") { menuItem -divider true -command $command; menuItem -label "argument(s):" -boldFont true -command $command; for ($j = 0; $j < $sizeArguments; $j++) { menuItem -label $arguments[$j] -command $command; } } setParent..; } else { menuItem -parent $userInterfaceItem -label $label -command $command; } } else { if ($rightClickOption[1] == 1) { $label = ($procNames[$n] + "(" + $procVars[$n] + ")"); } else { $label = ($procNames[$n] + "()"); } // if ($rightClickOption[2] == 1) { if ($procVars[$n] != "") { menuItem -parent $userInterfaceItem -label $label -subMenu true -command $command; menuItem -label ($procNames[$n] + "()") -command $command; menuItem -divider true -command $command; menuItem -label "argument(s):" -boldFont true -command $command; for ($j = 0; $j < $sizeArguments; $j++) { menuItem -label $arguments[$j] -command $command; } } else { menuItem -parent $userInterfaceItem -label $label -command $command; } } else { menuItem -parent $userInterfaceItem -label $label -command $command; } } } } } } /////////////////////////////////////////////////////////////////////////////////////////// global proc mmChangeExternalEditorPath() { string $externalEditorPath = `textField -query -text mmExternalEditorTextField`; if (`file -query -exists $externalEditorPath`) { print ("// set external editor to " + $externalEditorPath + "\n"); text -edit -label "" mmCheckExternalEditorPathTextField; } else { warning ("// file does not exists: " + $externalEditorPath + "\n"); text -edit -label " ->" -font "boldLabelFont" mmCheckExternalEditorPathTextField; } optionVar -stringValue "externalEditorPath" $externalEditorPath; } /////////////////////////////////////////////////////////////////////////////////////////// global proc mmDeleteMelScriptPath(int $ID) { string $melScriptDirs[] = `optionVar -query "melScriptDir"`; int $numMelScriptDirs = size($melScriptDirs); string $dirBuffer[]; clear $dirBuffer; int $k; for ($i = 0; $i < $numMelScriptDirs; $i++) { if ($i == $ID) { if ($melScriptDirs[$i] == "") { print ("// Delete pathID " + ($ID + 1) + "\n"); } else { print ("// Delete pathID " + ($ID + 1) + ": " + $melScriptDirs[$i] + "\n"); } } else { $dirBuffer[$k] = $melScriptDirs[$i]; $k++; } } int $sizeDirBuffer = size($dirBuffer); optionVar -remove "melScriptDir"; optionVar -stringValue "melScriptDir" $dirBuffer[0]; for ($i = 1; $i < $sizeDirBuffer; $i++) { optionVar -stringValueAppend "melScriptDir" $dirBuffer[$i]; } deleteUI mmDefineMelPathsUI; mmDefineMelPaths; if ((`window -exists mmListMelScriptsUI`) && (`textField -query -text ("mmMelScriptPathTextField" + ($ID -1))` != "")) { deleteUI mmListMelScriptsUI; mmListMelScripts; } } /////////////////////////////////////////////////////////////////////////////////////////// global proc mmChangeMelScriptPath(int $ID) { string $path = `textField -query -text ("mmMelScriptPathTextField" + $ID)`; if (`file -query -exists $path`) { print ("// Path " + ($ID + 1) + " changed to " + $path + "\n"); int $numMelScriptDirs = `optionVar -arraySize "melScriptDir"`; optionVar -clearArray "melScriptDir"; optionVar -stringValue "melScriptDir" `textField -query -text "mmMelScriptPathTextField0"`; for ($i = 1; $i < $numMelScriptDirs; $i++) { optionVar -stringValueAppend "melScriptDir" `textField -query -text ("mmMelScriptPathTextField" + $i)`; } if (`window -exists mmListMelScriptsUI`) { deleteUI mmListMelScriptsUI; mmListMelScripts; } text -edit -label (" " + ($ID + 1) + "") -font "plainLabelFont" ("mmMelScriptPathIntText" + $ID); } else { warning ("Path " + $ID + " does not exist: " + $path + "\n"); text -edit -label (" ->") -font "boldLabelFont" ("mmMelScriptPathIntText" + $ID); } } /////////////////////////////////////////////////////////////////////////////////////////// global proc mmAddScriptDirectory() { optionVar -stringValueAppend "melScriptDir" ""; int $ID = size(`optionVar -query "melScriptDir"`); print ("// Add pathID " + ($ID + 1) + "\n"); deleteUI mmDefineMelPathsUI; mmDefineMelPaths; } /////////////////////////////////////////////////////////////////////////////////////////// global proc mmChangeRightClickOptions() { int $rightClickOption[]; $rightClickOption[0] = `checkBox -query -value mmRightClickOptionsIndicateReturnType`; $rightClickOption[1] = `checkBox -query -value mmRightClickOptionsIndicateArguments`; $rightClickOption[2] = `checkBox -query -value mmRightClickOptionsIndicateShowProcedureInformation`; $rightClickOption[3] = `checkBox -query -value mmRightClickOptionsShowTooltips`; optionVar -clearArray "rightClickOptions"; optionVar -intValueAppend "rightClickOptions" $rightClickOption[0]; optionVar -intValueAppend "rightClickOptions" $rightClickOption[1]; optionVar -intValueAppend "rightClickOptions" $rightClickOption[2]; optionVar -intValueAppend "rightClickOptions" $rightClickOption[3]; if (`window -exists mmListMelScriptsUI`) { deleteUI mmListMelScriptsUI; mmListMelScripts; } } /////////////////////////////////////////////////////////////////////////////////////////// global proc mmDefineMelPaths() { int $numMelScriptDirs = `optionVar -arraySize "melScriptDir"`; string $melScriptDirs[] = `optionVar -query "melScriptDir"`; string $externalEditor = `optionVar -query "externalEditorPath"`; int $rightClickOption[] = `optionVar -query "rightClickOptions"`; int $width = 350; int $height = 400; string $changeCommand; if (`window -exists mmDefineMelPathsUI`) { deleteUI mmDefineMelPathsUI; } else { window -width ($width + 42) -height $height -title "mmListMelScripts Preferences" mmDefineMelPathsUI; scrollLayout -width ($width + 42); columnLayout -width $width; frameLayout -width ($width + 5) -label "1.) General Preferences:" -collapsable true; columnLayout -width ($width + 5); separator -width $width; checkBox -label "Show tooltips." -value $rightClickOption[3] -changeCommand mmChangeRightClickOptions mmRightClickOptionsShowTooltips; setParent..; setParent..; frameLayout -width ($width + 5) -label "2.) Right Click Preferences:" -collapsable true; columnLayout -width ($width + 5); separator -width $width; checkBox -label "List procedure's return type and argument(s) in sub-menu." -value $rightClickOption[2] -changeCommand mmChangeRightClickOptions mmRightClickOptionsIndicateShowProcedureInformation; checkBox -label "Indicate return type of procedures." -value $rightClickOption[0] -changeCommand mmChangeRightClickOptions mmRightClickOptionsIndicateReturnType; checkBox -label "Indicate argument(s) of procedures." -value $rightClickOption[1] -changeCommand mmChangeRightClickOptions mmRightClickOptionsIndicateArguments; setParent..; setParent..; frameLayout -width ($width + 5) -label "3.) Enter path of the external text editor below:" -collapsable true; columnLayout -width ($width + 5); separator -width $width; rowLayout -numberOfColumns 2 -columnWidth2 (ceil($width * 0.05)) (ceil($width * 0.95)); text -label "" mmCheckExternalEditorPathTextField; textField -width $width -text $externalEditor -changeCommand mmChangeExternalEditorPath mmExternalEditorTextField; setParent..; setParent..; setParent..; frameLayout -width ($width + 5) -label "4.) Enter path of script directories below:" -collapsable true; columnLayout -width ($width + 5); separator -width $width; for ($i = 0; $i < $numMelScriptDirs; $i++) { rowLayout -numberOfColumns 3 -columnWidth3 (ceil($width * 0.05)) (ceil($width * 0.83)) (ceil($width * 0.12)); text -label (" " + ($i + 1) + " ") ("mmMelScriptPathIntText" + $i); $changeCommand = "mmChangeMelScriptPath(" + $i + ")"; $deleteCommand = "mmDeleteMelScriptPath(" + $i + ")"; textField -width (ceil($width * 0.83)) -text $melScriptDirs[$i] -changeCommand $changeCommand ("mmMelScriptPathTextField" + $i); if ($i > 1) { button -width (ceil($width * 0.12)) -label "delete" -command $deleteCommand; } setParent..; } separator -width $width; button -label "Add an additional script directory" -width $width -command mmAddScriptDirectory -backgroundColor 0.9 0.8 0.9; setParent..; setParent..; button -width ($width + 4) -height 18 -backgroundColor 0.8 0.9 0.9 -align "left" -label "online help: www.manuelmacha.de/scripts/" -command "system(\"load http://www.manuelmacha.de/scripts/scripts.html\")"; window -edit -width ($width + 42) -height $height -title "mmListMelScripts Preferences" mmDefineMelPathsUI; showWindow mmDefineMelPathsUI; } } /////////////////////////////////////////////////////////////////////////////////////////// global proc mmExecuteMel(int $buttonID1, int $buttonID2) { string $userProc = `textField -query -text ("mmListMelScriptTextField" + $buttonID1 + "_" + $buttonID2)`; string $procNameParts[]; tokenize $userProc "()" $procNameParts; string $procTest = `whatIs $procNameParts[0]`; string $filter = `textField -query -text mmListMelScriptsTextFieldFilter`; string $melDirectories[] = `optionVar -query "melScriptDir"`; string $melScriptNames[] =`getFileList -folder ($melDirectories[$buttonID1] + "\\") -filespec ("*" + $filter + "*.mel")`; string $melScriptNamesParts[]; tokenize $melScriptNames[$buttonID2] "." $melScriptNamesParts; if ($procTest != "Unknown") { print ("// execute: " + $userProc + "\n"); eval $userProc; } else { warning ($userProc + " is not a valid procedure!"); // eval $melScriptNamesParts[0]; // print ("// execute: " + $melScriptNames[$buttonID2] + "\n"); } } /////////////////////////////////////////////////////////////////////////////////////////// global proc mmSourceMel(int $buttonID1, int $buttonID2) { string $filter = `textField -query -text mmListMelScriptsTextFieldFilter`; string $melDirectories[] = `optionVar -query "melScriptDir"`; string $melDirectoriesParts[]; string $melScriptNames[] =`getFileList -folder ($melDirectories[$buttonID1] + "\\") -filespec ("*" + $filter + "*.mel")`; string $directory = ($melDirectories[$buttonID1] + "\\"); string $directoryParts[]; int $numDirectoryParts = `tokenize $directory "\\" $directoryParts`; string $buffer = ""; for ($i = 0; $i < $numDirectoryParts; $i++) { if ($i == 0) { $buffer = $directoryParts[0]; } else { $buffer = ($buffer + "\\\\" + $directoryParts[$i]); } if ($i == ($numDirectoryParts - 1)) { $buffer = ($buffer + "\\\\"); } } string $script = $melScriptNames[$buttonID2]; string $completePath = ("source \"" + $buffer + $script + "\""); eval $completePath; print ("// " + $completePath); } /////////////////////////////////////////////////////////////////////////////////////////// global proc mmEditMel(int $buttonID1, int $buttonID2) { string $path = `optionVar -query "externalEditorPath"`; string $editorPath = ("start " + `optionVar -query "externalEditorPath"`); if (`file -query -exists $path`) { string $filter = `textField -query -text mmListMelScriptsTextFieldFilter`; string $melDirectories[] = `optionVar -query "melScriptDir"`; string $melDirectoriesParts[]; string $melScriptNames[] =`getFileList -folder ($melDirectories[$buttonID1] + "\\") -filespec ("*" + $filter + "*.mel")`; string $directory = ($melDirectories[$buttonID1] + "\\"); string $directoryParts[]; int $numDirectoryParts = `tokenize $directory "\\" $directoryParts`; string $buffer = ""; for ($i = 0; $i < $numDirectoryParts; $i++) { if ($i == 0) { $buffer = $directoryParts[0]; } else { $buffer = ($buffer + "\\" + $directoryParts[$i]); } if ($i == ($numDirectoryParts - 1)) { $buffer = ($buffer + "\\"); } } string $script = $melScriptNames[$buttonID2]; system ($editorPath + " \"" + $buffer + $script + "\""); print ("// " + $editorPath + " \"" + $buffer + $script + "\"\n"); } else { warning ("// the specified editor path does not exist: " + $path + " -> Please enter a valid path.\n"); } } /////////////////////////////////////////////////////////////////////////////////////////// global proc mmListMelScriptsFilter() { global string $mmMelScriptFilter; $mmMelScriptFilter = `textField -query -text mmListMelScriptsTextFieldFilter`; deleteUI mmListMelScriptsUI; mmListMelScripts; } /////////////////////////////////////////////////////////////////////////////////////////// global proc mmListMelScripts() { if (!`optionVar -exists "rightClickOptions"`) { optionVar -intValue "rightClickOptions" 0; //Indicate return type of procedures. optionVar -intValueAppend "rightClickOptions" 0; //Indicate arguments of procedures. optionVar -intValueAppend "rightClickOptions" 1; //List procedure's return type and argument(s) in sub-menu. optionVar -intValueAppend "rightClickOptions" 1; //Show tooltips. } if (!`optionVar -exists "melScriptDir"`) { optionVar -stringValue "melScriptDir" ""; optionVar -stringValueAppend "melScriptDir" ""; } if (!`optionVar -exists "externalEditorPath"`) { if (`file -query -exists "C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe"`) { optionVar -stringValue "externalEditorPath" "C:/Program Files/Windows NT/Accessories/wordpad.exe"; } else { optionVar -stringValue "externalEditorPath" ""; } } global string $mmMelScriptFilter; string $melDirectories[] = `optionVar -query "melScriptDir"`; string $melDirectories[] = `optionVar -query "melScriptDir"`; int $numMelDirectories = size($melDirectories); string $melScriptNames[]; string $melScriptNamesParts[]; int $numMelScriptNames; int $counter = 1; int $counterRows = 1; string $buttonID; string $postMenuCommand; string $annotation; int $options[] = `optionVar -query "rightClickOptions"`; if ($options[3] == 0) { $annotation = ""; } else { $annotation = "Use * as a wildcard."; } int $width = 250; int $height = 600; if (`window -exists mmListMelScriptsUI`) { deleteUI mmListMelScriptsUI; } else { window -width ($width + 32) -height $height -title "mmListMelScripts" mmListMelScriptsUI; scrollLayout -width ($width + 32) mmListMelScriptsScrollLayout1; columnLayout -width ($width + 32) mmListMelScriptsColumnLayout1; rowLayout -numberOfColumns 2 -columnWidth2 (ceil($width * 0.2)) (ceil($width * 0.8)); text -width (ceil($width * 0.2)) -annotation $annotation -label " Search:"; textField -width (ceil($width * 0.8)) -text $mmMelScriptFilter -changeCommand mmListMelScriptsFilter -annotation $annotation mmListMelScriptsTextFieldFilter; setParent..; separator -width $width; rowLayout -numberOfColumns 4 -columnWidth4 (ceil($width * 0.25)) (ceil($width * 0.24)) (ceil($width * 0.24)) (ceil($width * 0.27)); text -label " X = eXecute " -backgroundColor 0.8 0.9 0.9; text -label " S = Source " -backgroundColor 0.9 0.8 0.9; text -label " E = Edit " -backgroundColor 0.8 0.9 0.8; button -width (ceil($width * 0.26)) -height 16 -label "Preferences" -align "center" -command mmDefineMelPaths; setParent..; separator -width $width; if ($options[3] == 0) { $annotation = ""; } else { $annotation = "Right-click for more options."; } for ($i = 0; $i < $numMelDirectories; $i++) { $melScriptNames =`getFileList -folder ($melDirectories[$i] + "\\") -filespec ("*" + $mmMelScriptFilter + "*.mel")`; $numMelScriptNames = size($melScriptNames); frameLayout -width $width -collapsable true -collapse false -label $melDirectories[$i] ("mmListMelScriptsFrameLayout" + $i); if ($numMelScriptNames == 0) { frameLayout -edit -collapse true -visible false ("mmListMelScriptsFrameLayout" + $i); } else { $counterRows++; } columnLayout -width $width ("mmListMelScriptsSubColumnLayout" + $i); separator -width $width -style "out"; for ($k = 0; $k < $numMelScriptNames; $k++) { tokenize $melScriptNames[$k] "." $melScriptNamesParts; rowLayout -numberOfColumns 4 -columnAlign4 "center" "center" "center" "left" -columnWidth4 (ceil($width * 0.066)) (ceil($width * 0.066)) (ceil($width * 0.066)) (ceil($width * 0.8)) ("mmListMelScriptsSubRowLayout" + $i + "_" + $k); $buttonID = ("mmExecuteMel(" + $i + "," + $k + ")"); $changeText = ("mmChangeTextField(" + $i + "," + $k + ")"); $postMenuOptionCommand = ("mmListMelScriptsPostMenuOptionCommand(" + $i + "," + $k + ", 0)"); button -width (ceil($width * 0.066)) -align "center" -label "X" -backgroundColor 0.8 0.9 0.9 -command $buttonID -annotation $annotation ("mmListMelScriptButtonX_" + $i + "_" + $k); popupMenu -postMenuCommand $postMenuOptionCommand -postMenuCommandOnce true ("mmListMelScriptOptionMenuX_" + $i); $buttonID = ("mmSourceMel(" + $i + "," + $k + ")"); $postMenuOptionCommand = ("mmListMelScriptsPostMenuOptionCommand(" + $i + "," + $k + ", 1)"); button -width (ceil($width * 0.066)) -align "center" -label "S" -backgroundColor 0.9 0.8 0.9 -command $buttonID -annotation $annotation ("mmListMelScriptButtonS_" + $i + "_" + $k); popupMenu -postMenuCommand $postMenuOptionCommand -postMenuCommandOnce true ("mmListMelScriptOptionMenuS_" + $i); $buttonID = ("mmEditMel(" + $i + "," + $k + ")"); $postMenuOptionCommand = ("mmListMelScriptsPostMenuOptionCommand(" + $i + "," + $k + ", 2)"); button -width (ceil($width * 0.066)) -align "center" -label "E" -backgroundColor 0.8 0.9 0.8 -command $buttonID -annotation $annotation ("mmListMelScriptButtonE_" + $i + "_" + $k); $debug = `popupMenu -postMenuCommand $postMenuOptionCommand -postMenuCommandOnce true ("mmListMelScriptOptionMenuE_" + $i)`; textField -width (ceil($width * 0.78)) -text ($melScriptNamesParts[0] + "()") -changeCommand $changeText -annotation $annotation ("mmListMelScriptTextField" + $i + "_" + $k); $postMenuCommand = ("mmListMelScriptsPostMenuCommand(" + $i + "," + $k + ")"); popupMenu -postMenuCommand $postMenuCommand -postMenuCommandOnce true ("mmListMelScriptPopupMenu" + $i); setParent..; $counter++; separator -width $width; } clear $melScriptNames; setParent..; setParent..; } separator -width $width -style "double"; button -width $width -height 18 -backgroundColor 0.8 0.9 0.9 -align "left" -label "online help: www.manuelmacha.de/scripts/" -command "system(\"load http://www.manuelmacha.de/scripts/scripts.html\")"; int $dynamicHeight = (95 + ($counterRows * 22) + (($counter - 1) * 27)); if ($dynamicHeight < $height) { window -edit -width ($width + 32) -height $dynamicHeight mmListMelScriptsUI; } else { window -edit -width ($width + 32) -height $height mmListMelScriptsUI; } showWindow mmListMelScriptsUI; } } mmListMelScripts();