Hi all, I’m new to MEL scripting. I’ve been trying to make a script that will automate the process of making a matte pass for each material I have in a scene. It’s not fancy, but I managed to hack together something that doesn’t give me errors. I literally just want it to create two nodes (a pass and a customcolor) for each material and then connect them up in the right way (customcolor pass to the correct pass and evaluation pass through to the correct shader).
When I do the process manually, it works perfectly. But the script doesn’t seem to do it correctly, the passes are there in the channels, but they are blank. I hope that’s clear enough, if I didn’t explain it well I’d be happy to elaborate, I’m using Maya 2015. Here’s the script:
global proc RS_createRenderPasses()
{
string $buffer, $pass, $shader;
string $miaNodes[] = `ls -type "mia_material_x_passes"`;
// you can add passes to the array
// passes have to be after the attribute for this script to work!
string $passes[] = {"matte"};
// loop through all mia_material_x_passes shaders
for ($shader in $miaNodes)
{
// loop through passes
for ($pass in $passes)
{
// create scene pass if not existing
if (!`objExists ($pass + $shader)`)
{
// create custom color scene pass
$pass = `shadingNode -asRendering renderPass`;
applyAttrPreset renderPass1 "C:/Program Files/Autodesk/Maya2015/presets/attrPresets/renderPass/customColor.mel" 1;
$pass = `rename renderPass1 ($shader + "_matte")`;
// associate scene pass with default render layer
connectAttr -nextAvailable defaultRenderLayer.renderPass ($pass + ".owner");
}
// create buffer if not existing (every shader will need as many buffer nodes as you have passes!)
if (!`objExists ($pass + "_buffer_" + $shader)`)
{
// buffer will be named "passName_buffer_shaderName" (e.g. "refl_level_buffer_mia_material_x_passes1")
$buffer = `mrCreateCustomNode -asUtility "" writeToColorBuffer`;
$buffer = `rename $buffer ($pass + "_buffer_" + $shader)`;
// connect scene pass to buffer
connectAttr -f ($pass + ".message") ($buffer + ".renderPass");
//set matte color to red and pass to single channel
setAttr ($pass + ".numChannels") 1;
setAttr ($buffer + ".color") -type double3 1 0 0 ;
// connect shader to buffer
connectAttr -f ($shader + ".diffuse") ($buffer + ".evaluationPassThrough");
}
}
}
}
RS_createRenderPasses;
Any help would be amazingly appreciated!
Thank you