Recently, I’ve been using an outside file to do my Maya MEL rendering process.  There are some benefits to this technique.

First, you can always have a dedicated counter integer number no matter how many times you render a scripted sequence.  This is great when you are rendering a series of images, making changes to a model, then repeating the process.  When finished, you have a directory of a work-in-progress image sequence.

Another thing outside file data can be useful is to make changes to your MEL script as it runs.  As we all know, MEL scripts are not very good at allowing for manual modification in runtime.  Now we can have a bunch of environmental variables set by the user whenever they want.  It’s like having a slider in runtime.

One suggestion for all MEL script loops you may make is to set up a KILL.txt file.  Just in case you make an endless loop, have a conditional that always checks a simple 0 or 1 in the Kill text file.  This work around can save you a lot of time if you make the common mistake of not writing in a end conditional.

Lastly, among other multiple reasons for txt file controls, this is very useful for setting up standards for file saving, render image saving, and export saving directory strings.  It’s very annoying to put all your save locations across all MEL scripts.  This txt file technique can be saved in one location, thus allowing you to set up your project “set” and export paths quickly and without errors.

I made two functions, called GetTopLineTXTFile and ChangeTopLineTXTFile.  Now that I think about it, I probably should have followed standard Maya MEL command conventions and used SetTopLineTXTFile, but oh well.  It’s simple to use: make a text file, save the path, and install this MEL in your documents/maya/scripts folder.  Remember, MEL requires different “special” characters depending upon your operating system and string conventions.  In my example, I just used the double slash special character to force the final string to be a single slash.  There are different techniques for this, just make sure whatever you use will be compatible with MEL string objects.

Code:
int $YYY = GetTopLineTXTFile("c:\\mayacount.txt");
global proc int GetTopLineTXTFile(string $Path) {
//Nick Pisca 0001d, string $Path = "c:\\mayacount.txt";
string $exampleFileName = ( $Path );
string $s;
$fileId=`fopen $exampleFileName "r"`;
$s=`fread $fileId $s`;
fclose $fileId;
return $s;
}

Here’s the second command:  (note, this will overwrite your text file.  Use this with caution because there is no undo.)

Code:
global proc ChangeTopLineTXTFile(string $Path, int $NewValue) {
//Nick Pisca 0001d, string $Path = "c:\\mayacount.txt";
//ChangeTopLineTXTFile "c:\\mayacount.txt" 3;
string $exampleFileName = ( $Path );
string $s;
$fileId=`fopen $exampleFileName "w"`;
string $ConvStr = string($NewValue);
fwrite $fileId $ConvStr;
fclose $fileId;
}

Both of these functions have been on my wiki for a while.  Feel free to log on and add more functions and procedures if you like.

For some more standard techniques of multiple batch rendering (a name I gave for the process of batching the batch render sequence), take a look at Chapter 12 in my book YSYT.  Simple as it may appear, txt file modification from Maya may not be a task for a beginner.  Regardless, have fun coding.

Screencapture of Nick Pisca's Wiki, 2010

Screencapture of Nick Pisca's Wiki, 2010