getAttrAffectsCmd.cpp
#include <maya/MIOStream.h>
#include <maya/MString.h>
#include <maya/MItSelectionList.h>
#include <maya/MSelectionList.h>
#include <maya/MFnAttribute.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MObjectArray.h>
#include <maya/MGlobal.h>
#include <maya/MSimple.h>
DeclareSimpleCommand( getAttrAffects, PLUGIN_COMPANY, "3.0");
MStatus getAttrAffects::doIt( const MArgList& args )
{
MStatus stat;
MSelectionList list;
if ( args.length() > 0 ) {
MString argStr;
unsigned last = args.length();
for ( unsigned i = 0; i < last; i++ ) {
args.get( i, argStr );
list.add( argStr );
}
} else {
MGlobal::getActiveSelectionList( list );
}
MItSelectionList iter( list );
for ( ; !iter.isDone(); iter.next() )
{
MObject object;
stat = iter.getDependNode( object );
if ( !stat ) {
stat.perror("getDependNode");
continue;
}
MFnDependencyNode node( object );
cout << node.name() << ":\n";
unsigned i, numAttributes = node.attributeCount();
for (i = 0; i < numAttributes; ++i) {
MObject attrObject = node.attribute(i);
MFnAttribute attr;
unsigned j, affectedLen, affectedByLen;
attr.setObject (attrObject);
MObjectArray affectedAttributes;
node.getAffectedAttributes( attrObject, affectedAttributes );
affectedLen = affectedAttributes.length();
MObjectArray affectedByAttributes;
node.getAffectedByAttributes( attrObject, affectedByAttributes );
affectedByLen = affectedByAttributes.length();
if ( affectedLen > 0 || affectedByLen > 0 ) {
cout << " " << attr.name() << ":\n";
if ( affectedLen > 0 ) {
cout << " Affects(" << affectedLen << "):";
for (j = 0; j < affectedLen; ++j ) {
attr.setObject ( affectedAttributes[j] );
cout << " " << attr.name();
}
cout << endl;
}
if ( affectedByLen > 0 ) {
cout << " AffectedBy(" << affectedByLen << "):";
for (j = 0; j < affectedByLen; ++j ) {
attr.setObject ( affectedByAttributes[j] );
cout << " " << attr.name();
}
cout << endl;
}
}
}
}
return MS::kSuccess;
}