#include <maya/MFnPlugin.h>
#include <maya/MArgDatabase.h>
#include <maya/MPxCommand.h>
#include <maya/MGlobal.h>
#include <maya/MIOStream.h>
#include <maya/MSyntax.h>
#include <maya/MSelectionList.h>
#include <maya/MFnDependencyNode.h>
#define kFlagIcon "-i"
#define kFlagIconLong "-icon"
{
public:
nodeIcon();
~nodeIcon() override;
static void *creator();
};
nodeIcon::nodeIcon()
{
}
nodeIcon::~nodeIcon()
{
}
void *nodeIcon::creator()
{
return( new nodeIcon() );
}
bool nodeIcon::hasSyntax()
{
return( true );
}
{
kFlagIconLong,
return( syntax );
}
{
return( status );
}
bool queryUsed = argData.isQuery();
bool iconUsed = argData.isFlagSet( kFlagIcon );
status = argData.getObjects( sList );
if ( MS::kSuccess != status ) {
"nodeIcon: could not query the selection list" );
return( MS::kFailure );
}
if ( MS::kSuccess != status || 0 == count ) {
"nodeIcon: you need to specify at least one node" );
return( MS::kFailure );
}
if ( iconUsed ) {
kFlagIcon, 0, iconName ) );
} else if ( !queryUsed ) {
"nodeIcon: the -icon flag needs to be specified in edit mode" );
return( MS::kFailure );
}
int i;
for ( i = 0; i < count; i++ ) {
if ( MS::kSuccess != status ) {
"nodeIcon: only nodes can be selected" );
return( MS::kFailure );
}
if ( queryUsed ) {
result = nodeFn.icon( &status );
if ( MS::kSuccess != status ) {
"nodeIcon: could not query the icon assigned to the node" );
return( MS::kFailure );
}
} else {
status = nodeFn.setIcon( iconName );
if ( MS::kSuccess != status ) {
"nodeIcon: the filename specified by the -icon flag could not be opened" );
return( status );
}
result = iconName;
}
}
return( status );
}
{
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"10.0",
"Any" );
status = plugin.registerCommand( "nodeIcon", nodeIcon::creator,
nodeIcon::newSyntax );
if ( !status ) {
"nodeIcon: failed to register the plug-in" );
}
return( status );
}
{
status = plugin.deregisterCommand( "nodeIcon" );
if ( !status ) {
"nodeIcon: failed to deregister the plug-in" );
}
return( status );
}