i wrote the Api to print the selected objects' name in maya's output window ,
print others in the same way , wish help you.
// Copyright © wxt
//
// File: selCmd.cpp
//
// MEL Command: sel
//
// Author: Maya Plug-in Wizard 2.0
//
// Includes everything needed to register a simple MEL command with Maya.
//
#include
#include
#include
#include
#include
#include
// Use helper macro to register a command with Maya. It creates and
// registers a command that does not support undo or redo. The
// created class derives off of MPxCommand.
//
DeclareSimpleCommand( sel, "wxt", "8.0");
MStatus sel::doIt( const MArgList& args )
//
// Description:
// implements the MEL sel command.
//
// Arguments:
// args - the argument list that was passes to the command from MEL
//
// Return Value:
// MS::kSuccess - command succeeded
// MS::kFailure - command failed (returning this value will cause the
// MEL script that is being run to terminate unless the
// error is caught using a "catch" statement.
//
{
MStatus stat = MS::kSuccess;
// Since this class is derived off of MPxCommand, you can use the
// inherited methods to return values and set error messages
//
MSelectionList selection;
MGlobal::getActiveSelectionList( selection );
MDagPath dagPath;
MFnDagNode dagNode;
MItSelectionList iter( selection );
for ( ; !iter.isDone( ); iter.next( ) )
{
iter.getDagPath( dagPath );
dagNode.setObject( dagPath );
cout<<dagNode.name( )<<endl;
}
setResult( "sel command executed!\n" );
return stat;
}