Difference between revisions of "Maya Batch Render"

From Antoine Vienne | Wiki
Jump to navigation Jump to search
(Arnold - Windows - Create .bat render file only for animated frames)
 
(7 intermediate revisions by the same user not shown)
Line 9: Line 9:
 
=== Maxwell Batch Render - Windows ===
 
=== Maxwell Batch Render - Windows ===
 
<pre>
 
<pre>
"C:\Program Files\Autodesk\Maya2017\bin\Render.exe" -r maxwell -s 1 -e 100 -l RENDER_LAYER K:\YOUR_PROJECT\YOUR_FILE.ma
+
"C:\Program Files\Autodesk\Maya2018\bin\Render.exe" -r maxwell -s 1 -e 100 -l RENDER_LAYER K:\YOUR_PROJECT\YOUR_FILE.ma
 
pause()
 
pause()
  
 +
</pre>
 +
 +
=== Arnold Batch Render - Windows ===
 +
<pre>
 +
// For Legacy render layers
 +
 +
"C:\Program Files\Autodesk\Maya2018\bin\Render.exe" -r arnold -s 1 -e 100 -l RENDER_LAYER K:\YOUR_PROJECT\YOUR_FILE.ma
 +
pause()
 +
 +
// For Render setup layers
 +
 +
"C:\Program Files\Autodesk\Maya2018\bin\Render.exe" -r arnold -s 1 -e 100 -rl RENDER_LAYER K:\YOUR_PROJECT\YOUR_FILE.ma
 +
pause()
 +
 +
</pre>
 +
 +
=== V-Ray Batch Render - Windows ===
 +
<pre>
 +
"C:\Program Files\Autodesk\Maya2018\bin\Render.exe" -r vray -s 1 -e 100 -rl RENDER_LAYER K:\YOUR_PROJECT\YOUR_FILE.ma
 +
pause()
 +
 +
</pre>
 +
 +
=== Arnold - Windows - Batch render for student version ===
 +
<pre>
 +
// HOW TO - RENDER A LIST OF SHOTS WITHOUT ARNOLD BATCH RENDER LICENSE
 +
 +
// 1ST STEP
 +
// First, create a .bat which will look like this:
 +
// Replace path to maya.exe with your own path, and with paths to your .mel files - How many lines as you want to render shots/scenes.
 +
 +
 +
 +
 +
"C:\Program Files\Autodesk\Maya2018\bin\maya.exe" -script C:\YOUR_PATH\shot1.mel
 +
 +
"C:\Program Files\Autodesk\Maya2018\bin\maya.exe" -script C:\YOUR_PATH\shot2.mel
 +
 +
popd
 +
 +
pause
 +
 +
 +
 +
 +
// 2ND STEP
 +
// CREATE A .mel FILE FOR EACH SHOT/SCENE AS FOLLOWING
 +
 +
 +
 +
 +
////////
 +
//// PATH TO FILE YOU WANT TO RENDER
 +
////////
 +
 +
file -f -o "C:\YOUR_PATH\your_scene_001.mb";
 +
 +
////////
 +
//// NOTHING TO CHANGE HERE
 +
////////
 +
 +
// RENDER ALL ENABLED LAYERS AND RENDER ALL ENABLED CAMERAS
 +
renderSequenceOptionsWindow;
 +
optionVar -intValue "renderSequenceAllLayers" 1;
 +
optionMenuGrp -edit -enable false renderSequenceCameraList; optionVar -intValue "renderSequenceAllCameras" 1;
 +
 +
// REFRESH MAYA UI TO ALLOW SEQUENCE RENDER
 +
// THANKS TO RODOLPHE VAILLANT http://rodolphe-vaillant.fr
 +
global proc mel_process_idle_events()
 +
{
 +
    // '$list' contains all the current events/commands in the idle queue
 +
    string $list[] = `evalDeferred -list`;
 +
    // The timer is here for safety
 +
    // you could use a counter or the mel command 'progressWindow'
 +
    timer -startTimer;
 +
    while( (size($list) > 0) )
 +
    {
 +
        // Idle events might spawn more idle events so we need to
 +
        // loop until the list is empty
 +
        python("maya.utils.processIdleEvents()");
 +
        $list = `evalDeferred -list`;
 +
        // Stop processing idle events after 15 seconds
 +
        if( `timer -lap` > 15)
 +
            break;
 +
    }
 +
    timer -endTimer;
 +
}
 +
// display the "Tool settings" pannel:
 +
toolPropertyWindow -inMainWindow true;
 +
updateMainWindowComponentState();
 +
// Wait for UI to refresh:
 +
mel_process_idle_events();
 +
// safely access UI elements:
 +
button -visible false "someButtonInTheToolSettingsWindow";
 +
 +
////////
 +
//// CUSTOM PARAMETERS
 +
////////
 +
 +
// SET START FRAME
 +
setAttr "defaultRenderGlobals.startFrame" 1;
 +
 +
// SET END FRAME
 +
setAttr "defaultRenderGlobals.endFrame" 100;
 +
 +
// DISABLE ALL RENDER LAYERS
 +
$selected=`ls -type "renderLayer"`;
 +
for ($object in $selected){
 +
    renderLayerEditorRenderable RenderLayerTab $object "0";
 +
}
 +
 +
// SET RENDER LAYER TO RENDER
 +
renderLayerEditorRenderable RenderLayerTab defaultRenderLayer "1";
 +
 +
////////
 +
//// GENERAL RENDER SETTINGS
 +
////////
 +
 +
// SET IMAGE FILE PREFIX
 +
setAttr -type "string" defaultRenderGlobals.imageFilePrefix "<Scene>/<RenderLayer>/<Scene>_<RenderLayer>_<Camera>";
 +
 +
// SET IMAGE FORMAT TO EXR
 +
setAttr -type "string" defaultArnoldDriver.ai_translator "exr";
 +
 +
// SET MERGE AOVS ON
 +
setAttr "defaultArnoldDriver.mergeAOVs" 1;
 +
 +
// SET FRAME EXTENSION WITH FRAME PADDING FOR ANIMATION
 +
setMayaSoftwareFrameExt("3", 0);
 +
 +
// SET RESOLUTION
 +
editRenderLayerGlobals -currentRenderLayer defaultRenderLayer;
 +
setAttr defaultResolution.width 1920;
 +
setAttr defaultResolution.height 1080;
 +
 +
$width = `getAttr defaultResolution.width`;
 +
$height = `getAttr defaultResolution.height`;
 +
$deviceAspect = (float($width)/float($height));
 +
setAttr defaultResolution.deviceAspectRatio $deviceAspect;
 +
 +
////////
 +
//// NOTHING TO CHANGE HERE
 +
////////
 +
 +
// RENDER
 +
RenderSequence;
 +
//print"RENDER_FINISHED";
 +
 +
// SAVE
 +
//file -f -save;
 +
 +
// QUIT MAYA
 +
evalDeferred("quit -f");
 +
 +
</pre>
 +
 +
=== Arnold - Windows - Create .bat render file only for animated frames ===
 +
<pre>
 +
// CHANGE PATH TO YOUR MAYA SCENE AND SPECIFY YOUR RENDER LAYER
 +
// THEN EXECUTE THIS MEL
 +
// SAVE BAT WHEN NOTEPAD OPENS AND EXECUTE IT
 +
 +
// SET PATH TO MAYA SCENE
 +
string $mayaScenePath = "K:\\YOUR_PROJECT\\YOUR_FILE.ma";
 +
 +
// SET NAME OF LAYER TO RENDER
 +
string $layerToRender = "defaultRenderLayer";
 +
 +
 +
// LIST OF FRAMES WITH KEYS ON ALL TRANSFORM OBJECTS
 +
$selected=`ls -dag -et transform`;
 +
float $keysSelected[] = `keyframe -query $selected`;
 +
float $sorted[] = python("import pymel.core as pm; list(set((pm.getMelGlobal(\"float[]\", \"$keysSelected\"))))");
 +
 +
// COUNT FRAMES WITH KEYS
 +
$nbreKeysFrames=size($sorted);
 +
 +
// PATH TO MAYA RENDER
 +
string $mayaBatch = "C:\\Program Files\\Autodesk\\Maya2019\\bin\\Render.exe";
 +
string $mayaBatchPath = ("\"" + $mayaBatch + "\"");
 +
 +
// CREATE LIST OF RENDER COMMANDS FOR EACH FRAME
 +
string $renderCommands[];
 +
for ($i=0; $i<$nbreKeysFrames; ++$i)
 +
{
 +
    $renderCommands[$i] = ( $mayaBatchPath + " -r arnold -s " + $sorted[$i] + " -e " + $sorted[$i] + " -l " + $layerToRender + " " + $mayaScenePath);
 +
}
 +
 +
// CREATE BAT FILE TO EXECUTE
 +
string $batFile = "tmp.bat";
 +
string $batEnd = "pause()";
 +
stringArrayInsertAtIndex(size($renderCommands), $renderCommands, $batEnd);
 +
string $myScriptDir = `internalVar -utd`;
 +
string $tmpfile = $myScriptDir+$batFile;
 +
int $result = fwriteAllLines($tmpfile,$renderCommands);
 +
exec("notepad "+$tmpfile);
 
</pre>
 
</pre>

Latest revision as of 18:24, 13 May 2021

Maya .bat Batch Render Scripts

Redshift Batch Render - Windows

"C:\Program Files\Autodesk\Maya2018\bin\Render.exe" -r redshift -s 1 -e 100 -rl RENDER_LAYER K:\YOUR_PROJECT\YOUR_FILE.ma
pause()

Maxwell Batch Render - Windows

"C:\Program Files\Autodesk\Maya2018\bin\Render.exe" -r maxwell -s 1 -e 100 -l RENDER_LAYER K:\YOUR_PROJECT\YOUR_FILE.ma
pause()

Arnold Batch Render - Windows

// For Legacy render layers

"C:\Program Files\Autodesk\Maya2018\bin\Render.exe" -r arnold -s 1 -e 100 -l RENDER_LAYER K:\YOUR_PROJECT\YOUR_FILE.ma
pause()

// For Render setup layers

"C:\Program Files\Autodesk\Maya2018\bin\Render.exe" -r arnold -s 1 -e 100 -rl RENDER_LAYER K:\YOUR_PROJECT\YOUR_FILE.ma
pause()

V-Ray Batch Render - Windows

"C:\Program Files\Autodesk\Maya2018\bin\Render.exe" -r vray -s 1 -e 100 -rl RENDER_LAYER K:\YOUR_PROJECT\YOUR_FILE.ma
pause()

Arnold - Windows - Batch render for student version

// HOW TO - RENDER A LIST OF SHOTS WITHOUT ARNOLD BATCH RENDER LICENSE

// 1ST STEP
// First, create a .bat which will look like this:
// Replace path to maya.exe with your own path, and with paths to your .mel files - How many lines as you want to render shots/scenes.




"C:\Program Files\Autodesk\Maya2018\bin\maya.exe" -script C:\YOUR_PATH\shot1.mel

"C:\Program Files\Autodesk\Maya2018\bin\maya.exe" -script C:\YOUR_PATH\shot2.mel

popd

pause




// 2ND STEP
// CREATE A .mel FILE FOR EACH SHOT/SCENE AS FOLLOWING




////////
//// PATH TO FILE YOU WANT TO RENDER
////////

file -f -o "C:\YOUR_PATH\your_scene_001.mb";

////////
//// NOTHING TO CHANGE HERE
////////

// RENDER ALL ENABLED LAYERS AND RENDER ALL ENABLED CAMERAS
renderSequenceOptionsWindow;
optionVar -intValue "renderSequenceAllLayers" 1;
optionMenuGrp -edit -enable false renderSequenceCameraList; optionVar -intValue "renderSequenceAllCameras" 1;

// REFRESH MAYA UI TO ALLOW SEQUENCE RENDER
// THANKS TO RODOLPHE VAILLANT http://rodolphe-vaillant.fr
global proc mel_process_idle_events()
{
    // '$list' contains all the current events/commands in the idle queue
    string $list[] = `evalDeferred -list`;
    // The timer is here for safety
    // you could use a counter or the mel command 'progressWindow'
    timer -startTimer;
    while( (size($list) > 0) )
    {
        // Idle events might spawn more idle events so we need to
        // loop until the list is empty
        python("maya.utils.processIdleEvents()");
        $list = `evalDeferred -list`;
        // Stop processing idle events after 15 seconds
        if( `timer -lap` > 15)
            break;
    }
    timer -endTimer;
}
// display the "Tool settings" pannel:
toolPropertyWindow -inMainWindow true;
updateMainWindowComponentState();
// Wait for UI to refresh:
mel_process_idle_events();
// safely access UI elements:
button -visible false "someButtonInTheToolSettingsWindow";

////////
//// CUSTOM PARAMETERS
////////

// SET START FRAME
setAttr "defaultRenderGlobals.startFrame" 1;

// SET END FRAME
setAttr "defaultRenderGlobals.endFrame" 100;

// DISABLE ALL RENDER LAYERS
$selected=`ls -type "renderLayer"`;
for ($object in $selected){
    renderLayerEditorRenderable RenderLayerTab $object "0";
}

// SET RENDER LAYER TO RENDER
renderLayerEditorRenderable RenderLayerTab defaultRenderLayer "1";

////////
//// GENERAL RENDER SETTINGS
////////

// SET IMAGE FILE PREFIX
setAttr -type "string" defaultRenderGlobals.imageFilePrefix "<Scene>/<RenderLayer>/<Scene>_<RenderLayer>_<Camera>";

// SET IMAGE FORMAT TO EXR
setAttr -type "string" defaultArnoldDriver.ai_translator "exr";

// SET MERGE AOVS ON
setAttr "defaultArnoldDriver.mergeAOVs" 1;

// SET FRAME EXTENSION WITH FRAME PADDING FOR ANIMATION
setMayaSoftwareFrameExt("3", 0);

// SET RESOLUTION
editRenderLayerGlobals -currentRenderLayer defaultRenderLayer;
setAttr defaultResolution.width 1920;
setAttr defaultResolution.height 1080;

$width = `getAttr defaultResolution.width`;
$height = `getAttr defaultResolution.height`;
$deviceAspect = (float($width)/float($height));
setAttr defaultResolution.deviceAspectRatio $deviceAspect;

////////
//// NOTHING TO CHANGE HERE
////////

// RENDER
RenderSequence;
//print"RENDER_FINISHED";

// SAVE
//file -f -save;

// QUIT MAYA
evalDeferred("quit -f");

Arnold - Windows - Create .bat render file only for animated frames

// CHANGE PATH TO YOUR MAYA SCENE AND SPECIFY YOUR RENDER LAYER
// THEN EXECUTE THIS MEL
// SAVE BAT WHEN NOTEPAD OPENS AND EXECUTE IT

// SET PATH TO MAYA SCENE
string $mayaScenePath = "K:\\YOUR_PROJECT\\YOUR_FILE.ma";

// SET NAME OF LAYER TO RENDER
string $layerToRender = "defaultRenderLayer";


// LIST OF FRAMES WITH KEYS ON ALL TRANSFORM OBJECTS
$selected=`ls -dag -et transform`;
float $keysSelected[] = `keyframe -query $selected`;
float $sorted[] = python("import pymel.core as pm; list(set((pm.getMelGlobal(\"float[]\", \"$keysSelected\"))))");

// COUNT FRAMES WITH KEYS
$nbreKeysFrames=size($sorted);

// PATH TO MAYA RENDER
string $mayaBatch = "C:\\Program Files\\Autodesk\\Maya2019\\bin\\Render.exe";
string $mayaBatchPath = ("\"" + $mayaBatch + "\"");

// CREATE LIST OF RENDER COMMANDS FOR EACH FRAME
string $renderCommands[];
for ($i=0; $i<$nbreKeysFrames; ++$i)
{
    $renderCommands[$i] = ( $mayaBatchPath + " -r arnold -s " + $sorted[$i] + " -e " + $sorted[$i] + " -l " + $layerToRender + " " + $mayaScenePath);
}

// CREATE BAT FILE TO EXECUTE
string $batFile = "tmp.bat";
string $batEnd = "pause()";
stringArrayInsertAtIndex(size($renderCommands), $renderCommands, $batEnd);
string $myScriptDir = `internalVar -utd`;
string $tmpfile = $myScriptDir+$batFile;
int $result = fwriteAllLines($tmpfile,$renderCommands);
exec("notepad "+$tmpfile);