Node Connections

 

 

 

Nodes within the Maya API can be connected together by plugging one attribute into another. There are occasions when we need to traverse these connections between nodes.

We can do this by using MPlugs and the connectedTo() member function.

 

 

 

 

Accessing Connections To and From Attributes

Given an MPlug to a specific attribute, we can use the connectedTo member function to query connections to that node. The connectedTo member function takes 3 parameters; The first parameter will hold the returned list of attribute plugs; The 2nd and 3rd parameters determine whether destination or source plugs are returned.

To retrieve a list of input connections to this attribute, we simply ask connectedTo to return the connections where this plug is used as the destination. We can do the same thing for the output plugs.

 

 

 

 


#include<maya/MPlug.h>
#include<maya/MPlugArray.h>

void PrintConnections(MPlug& plug)
{
 

// will hold the connections to this node
MPlugArray plugs;

cout << "plug " << plug.name().asChar() << endl;

// get input plugs

plug.connectedTo(plugs,true,false);

cout << "\tinputs " << plugs.length() << endl;
for(int i=0;i<plugs.length();++i) {

  cout<<"\t\t"<< plugs[i].name().asChar() <<endl;

}


// get output plugs

plug.connectedTo(plugs,false,true);

cout << "\toutputs " << plugs.length() << endl;
for(int i=0;i<plugs.length();++i) {

  cout<<"\t\t"<< plugs[i].name().asChar() <<endl;

}

}

 

 

Accessing Connections To and From Nodes

 

Using the function set MFnDependencyNode you can use the getConnections member function to return a list of all attributes on the node that have connections.

 

We can then use the same process described above to access the attributes on the nodes it connects to.

 

 


#include<maya/MPlug.h>
#include<maya/MPlugArray.h>

void PrintNodeConnections(MObject& node)
{
 

// will hold the connections to this node
MPlugArray nodeplugs;

MFnDependencyNode fn(node);

cout << "node " << fn.name().asChar() << endl;

// using the getConnections function we return a list
// of attributes on THIS node that have connections.
fn.getConnections(nodeplugs);

cout << "numplugs " << nodeplugs.length() << endl;
for(int i=0;i<nodeplugs.length();++i) {

  // use function from above to print all of the
// connected attributes.

PrintConnections
( nodeplugs[i] );

}

}




 

 

What Next?

Traversing the Scene

Accessing Attributes

index

Rob Bateman [2004]

[HOME] [MEL] [API]