Accessing Display Layers [MEL]



 

 

Display Layers are used within maya to logically group a collection of objects. An animators main use of layers, is usually to group sets of animation controls together. There is however a lot of scope to use layers to say group the transforms which you will export animation for; or to split the character into upper and lower body bone sets etc. Ultimately each layer node will be connected to the items that are a part of that layer. To find this set of objects we merely need to query all outgoing connections.

 

 

 

 


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

// create an iterator to go through all meshes
void OutputDisplayLayers()
{
 

// iterate through all display layers
MItDependencyNodes it(MFn::kDisplayLayer);

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

 

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

// ignore the default layer
if( fn.name() == "defaultLayer" ) continue;

cout << "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?

Render Layers

index

Rob Bateman [2004]

[HOME] [MEL] [API]