/* '' Author: Jeremiah Grant '' Mel Lister is a basic manager for mel scripts. '' '' It allows for viewing and editing mel scripts from a given folder. '' All functionality is via the RMB. '' '' You can email me at jeremiah@jeremiahgrant.com '' Website: www.jeremiahgrant.com '' '' '' Credits: Help Window based off of scripts by David Walden, www.davidwalden.com */ // Global Variables. // // $melDirectory is the directory that the mel files are loaded from // // $saveMelDir is where the edited script will be saved // global string $melDirectory = ""; global string $saveMelDir = ""; // // Takes the info from getMelDir and takes off the actual file from the directory // global proc importFolder( string $filename, string $fileType ) { global string $melDirectory; string $filenameArray[]; int $arraySize, $count = 0; string $directory; tokenize $filename "/" $filenameArray; print $filenameArray; $arraySize = `size($filenameArray)`; for ($count ; $count<($arraySize-1) ; $count++) { $directory +=($filenameArray[$count]+"/"); } print $directory; // Testing $melDirectory = $directory; } // // Just calls fileBrowserDialog to select a file. // Actual file will be stripped to leave just the directory. // global proc getMelDir(string $textList) { fileBrowserDialog -m 0 -fc "importFolder" -ft "mel" -an "Mel Script" -om "Reference"; repopulateList $textList; } // // Repopulates the list from loading a new folder // global proc repopulateList(string $textList) { global string $melDirectory; string $melList[] = `getFileList -folder $melDirectory -filespec "*.mel"`; string $inMelList; textScrollList -e -ra $textList; for($inMelList in $melList) { textScrollList -e -append $inMelList $textList; } if($inMelList != "") textScrollList -e -sii 1 $textList; } // // Here is the main UI for melList // global proc melListUI() { global string $melDirectory; if (`window -ex melListWin`) deleteUI melListWin; // Get list of all MEL Scripts in given directory string $melList[] = `getFileList -folder $melDirectory -filespec "*.mel"`; string $inMelList; window -title "Mel List" -s 0 -rtf 1 -mnb 1 -mxb 0 -w 300 -menuBar 1 melListWin; menu -label "Help"; menuItem -label "Help" -c "scriptHelp"; rowColumnLayout -nc 3 -columnWidth 1 175 -columnWidth 2 10 -columnWidth 3 300; text "Mel Scripts"; separator -style "none"; text "Edit Script Field"; string $textList = `textScrollList -w 175 -numberOfRows 15 -ams 0 -aas 1 -shi 4 -dcc "melDescription `textScrollList -q -si scriptList`" scriptList`; separator -style "none"; string $editField = `scrollField -wordWrap 0 -w 300 -h 200 editField`; popupMenu -p $textList -b 3; menuItem -l "Description" -c "melDescription `textScrollList -q -si scriptList`"; menuItem -l "Load Script" -c "melLoad `textScrollList -q -si scriptList`"; menuItem -l "Load Folder" -c ("getMelDir "+$textList); menuItem -l "Edit Script" -c ("melEdit " + $editField + " " + "`textScrollList -q -si scriptList`"); popupMenu -p $editField -b 3; menuItem -l "Save Script" -c ("saveScript " + $editField); menuItem -l "Clear Editor" -c ("scrollField -e -cl "+$editField); // Initial loading of a work Folder getMelDir $textList; showWindow melListWin; } // // The description of the Script... located at the beginning of each file. // global proc melDescription(string $script[]) { global string $melDirectory; string $dirPlusScript, $nextLine; string $completeDes, $winName, $window; string $quote = "\""; int $count = 0; string $description[]; $winName = $script[0]+"WIN"; window -rtf 1 -title ($script[0] + " Description") $winName; columnLayout -adjustableColumn true; $dirPlusScript = $melDirectory+$script[0]; $fileId=`fopen $dirPlusScript "r"`; $nextLine = `fgetline $fileId`; // max 6 lines of description for($count; $count < 6; $count++) { $description[$count] = ""; $description[$count] = $nextLine; $nextLine = `fgetline $fileId`; } fclose $fileId; $completeDes = ($description[0] + $description[1] + $description[2] + $description[3] + $description[4] + $description[5]); text -label $completeDes -align "left"; showWindow; } // // Trying to get the damn thing to source // global proc melLoad(string $script[]) { global string $melDirectory; string $dirPlusScript; $dirPlusScript = ("\"" + $melDirectory+$script[0] + "\""); // dirname( $dirPlusScript ); // source "dirname"; eval( "source " + $dirPlusScript ); print $dirPlusScript; rehash; } // // Open the file in the Editor Field // global proc melEdit(string $editField, string $script[]) { global string $melDirectory; string $dirPlusScript, $nextLine, $fullEdit, $inFile; string $file[]; int $count = 0; $dirPlusScript = $melDirectory+$script[0]; $fileId=`fopen $dirPlusScript "r"`; $nextLine = `fgetline $fileId`; // max 6 lines of description while(!`feof $fileId`) { $file[$count] = $nextLine; $nextLine = `fgetline $fileId`; $count++; } fclose $fileId; for($inFile in $file) { $fullEdit += $inFile; } // Clear it first scrollField -e -cl $editField; // Now put the code in the box scrollField -e -it $fullEdit $editField; } // // This writes the edited script to a file // global proc saveScript(string $script) { print "This procedure will save this script to a file.\n\n"; string $newScript = `scrollField -q -tx $script`; // Test to see if there is anything to save. if( $newScript == "" ) { error "There is nothing to save."; } else { fileBrowserDialog -m 1 -fc "saveDir" -ft "mel" -an "Save As" -om "Reference"; global string $saveMelDir; string $object; int $fileOut; $fileOut=`fopen $saveMelDir "w"`; if ($fileOut == 0) { error "Location Invalid: Unable to write file"; } // Write it to the file fprint $fileOut $newScript; fclose $fileOut; print ("\n" + $saveMelDir); } } // // Just the command called from saveScript fileBrowserDialog. Gets the save directory. // global proc saveDir( string $filename, string $fileType ) { global string $saveMelDir; $saveMelDir = $filename; } // // Help Procedure // global proc scriptHelp() { if (`window -ex helpUI`) deleteUI helpUI; window -t "Mel Lister Help" -wh 450 350 helpUI; string $form = `formLayout`; string $scroll = `scrollLayout`; columnLayout; rowColumnLayout -nc 2 -cw 1 75 -cw 2 300; text -label "Created by: " -font boldLabelFont; text -label "Jeremiah Grant: www.JeremiahGrant.com"; setParent..; text -label "" -h 30; text -label " About: " -font boldLabelFont; string $noteText = " Mel Lister is a basic manager for scripts. All functionality is located in the \n" ; $noteText += " right mouse menu. This script takes all the mel scripts located in the same folder as the \n"; $noteText += " selected script and allows for Loading, Editing and Descriptions for the scripts loaded.\n"; $noteText += " \n"; $noteText += " The Script List menu consists of Description, Load Script, Load Folder and Edit Script. \n"; $noteText += " \n"; $noteText += " Description: Opens a dialog window with the first 6 lines of the file. To add your own \n"; $noteText += " description, edit the selected script. In the first 6 lines add your description.\n"; $noteText += " \n"; $noteText += " Load Script: Sources the script in Maya. \n"; $noteText += " \n"; $noteText += " Load Folder: Opens a file browser dialog. Select a mel script in the directory that you \n"; $noteText += " wish to load. \n"; $noteText += " \n"; $noteText += " Edit Script: Loads the selected script into the Editing Field.\n"; $noteText += " \n"; $noteText += " \n"; $noteText += " The Edit Field menu consists of Save Script and Clear Editor. \n"; $noteText += " \n"; $noteText += " Save Script: Opens a save dialog to save the edited script. \n"; $noteText += " \n"; $noteText += " Clear Editor: Clears the Editing Field\n"; $noteText += " \n"; $noteText += " \n"; $noteText += " Feel free to email me at jeremiah@jeremiahgrant.com. \n"; text -label $noteText -align left; text -label "" -h 10; setParent..; setParent..; string $closeButton = `button -label "Close Window" -c "deleteUI helpUI"`; setParent..; formLayout -e -attachForm $scroll left 0 -attachForm $scroll top 0 -attachForm $scroll right 0 -attachControl $scroll bottom 0 $closeButton -attachForm $closeButton left 0 -attachNone $closeButton top -attachForm $closeButton right 0 -attachForm $closeButton bottom 0 $form; showWindow helpUI; } melListUI; print "Mel List Written by Jeremiah Grant - 2004";