Accessing Render Layers [MEL]



Render Layers are used within maya to split a scene into multiple render passes. An MFn::kRenderLayer node will exist for each render layer, and will be connected to each of the set members. To find the list of objects, we simply need to query the outgoing connections from the render layer node.






void OutputRenderLayers()


// iterate through all render layers
MItDependencyNodes it(MFn::kRenderLayer);

for( ; !it.isDone(); )


// attach a function set to the layer
MFnDependencyNode fn(it.item());

// ignore the default render layers
if( == "defaultRenderLayer" ) continue;
if( == "globalRender" ) continue;

cout << "RENDER_LAYER " << << " {\n";

// get connections to attributes on the layer node.
// The LayerConnections will be a set of attributes
// on the LayerNode that are connected to something else.

MPlugArray LayerConnections;

// loop through all of the connections to the layer
for(unsigned int i=0;i<LayerConnections.length();++i)


// get the attribute plug on the other node so
// we can find out what it's connected to.

MPlugArray ConnectedNodes;
for( unsigned int j=0;j<ConnectedNodes.length();++j)


// attach a function set to the layer item.
MFnDependencyNode fnItem(ConnectedNodes[j].node());

// write the name of the item
cout << "\t" << << endl;


cout << "}" << endl;





What Next?

Display Layers


Rob Bateman [2004]