Alright! New version! This version now displays a progress bar while rendering, which also allows the user to cancel the rendering by pressing the ESC key. It also now has support for frame padding, of which the number can be easily controlled with the nFramePadLength variable. The last change is that it will also render in any selected image format from the render globals, not just iff!
Hope you guys enjoy!
-John Mather
Code:
// Batch rendering workaround V4 - John Mather (NextDesign)
// Author page: https://www.creativecrash.com/users/john-mather
// Check for updates here: https://simplymaya.com/forum/showthread.php?p=318227
string $filename = "render";
int $startFrame = 3;
int $endFrame = 24;
int $nFramePadLength = 4; // eg name.0000.ext (4 zeros)
string $directory = (`workspace -q -rd` + "images/");
// check for render panel. Found here: https://www.creativecrash.com/forums/mel/topics/error-object-not-found-renderview
string $renderPanel;
string $renderPanels[] = `getPanel -scriptType "renderWindowPanel"`;
if(size($renderPanels))
$renderPanel = $renderPanels[0];
else
{
$renderPanel = `scriptedPanel -type "renderWindowPanel" -unParent renderView`;
scriptedPanel -e -label "Render View" $renderPanel;
}
// get the image format in the render globals
int $format = `getAttr "defaultRenderGlobals.imageFormat"`;
string $extension = "";
switch($format)
{
case 0: $extension = "gif"; break;
case 1: $extension = "pic"; break;
case 2: $extension = "rla"; break;
case 3: $extension = "tif"; break;
case 4: $extension = "tif"; break;
case 5: $extension = "sgi"; break;
case 6: $extension = "als"; break;
case 7: $extension = "iff"; break;
case 8: $extension = "jpg"; break;
case 9: $extension = "eps"; break;
case 10: $extension = "iff"; break;
case 11: $extension = "cin"; break;
case 12: $extension = "yuv"; break;
case 13: $extension = "sgi"; break;
case 19: $extension = "tga"; break;
case 20: $extension = "bmp"; break;
case 22: $extension = "mov"; break;
case 30: $extension = "pntg"; break;
case 31: $extension = "psd"; break;
case 32: $extension = "png"; break;
case 33: $extension = "pict"; break;
case 34: $extension = "qtif"; break;
case 35: $extension = "dds"; break;
case 36: $extension = "psd"; break;
}
// start the progress bar
global string $gMainProgressBar;
progressBar -edit -beginProgress -isInterruptable true -status "Rendering..." -maxValue $endFrame $gMainProgressBar;
for ($i = $startFrame; $i <= $endFrame; $i++)
{
// check for user termination
if(`progressBar -query -isCancelled $gMainProgressBar`)
break;
currentTime $i;
renderWindowRender redoPreviousRender renderView;
// pad the frame number
string $framePadded = $i;
while (`size($framePadded)` < $nFramePadLength)
$framePadded = ("0" + $framePadded);
string $concatFilename = $directory + $filename + "." + $framePadded + "." + $extension;
if (`getApplicationVersionAsFloat` >= 2011)
// Thanks to nowayfra on creativecrash for his workaround
catch(eval(renderWindowSaveImageCallback ($renderPanel, $concatFilename, `getAttr defaultRenderGlobals.imageFormat`)));
else
renderWindowSaveImageCallback ($renderPanel, $concatFilename, `getAttr defaultRenderGlobals.imageFormat`);
progressBar -edit -step 1 -status ("Rendering frame " + (($i - $startFrame) + 1) + " of " + (($endFrame - $startFrame) + 1)) $gMainProgressBar; // update the progress bar
print ("Saved " + $concatFilename + "\n");
}
progressBar -edit -endProgress $gMainProgressBar; // clear the progress bar
print ("Completed rendering of " + (($endFrame - $startFrame) + 1) + " frames.\n");
Imagination is more important than knowledge.
Last edited by NextDesign; 18-09-2011 at 10:52 PM.