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.

 

 

 

 


#include<maya/MFnDagNode.h>
#include<maya/MItDependencyNodes.h>

void OutputRenderLayers()
{

 

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

for( ; !it.isDone(); it.next() )
{

 

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

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

cout << "RENDER_LAYER " << fn.name().asChar() << " {\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;
fn.getConnections(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;
LayerConnections[i].connectedTo(ConnectedNodes,false,true);
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" << fnItem.name().asChar() << endl;

}

}
cout << "}" << endl;

}

}



 

 

What Next?

Display Layers

index

Rob Bateman [2004]


[HOME] [MEL] [API]