hi all,
I write a simple command "testcmd", which has a paramter. But when I run this command:
testcmd -particleName "aaa";
it always complain that :
// Error:
Error detected in e:...\consoledebug.cpp, line 41: (kFailure): Unexpected Internal Failure //
// Error:
Error detected in e:...\consoledebug.cpp, line 41: (kFailure): Unexpected Internal Failure //
// Error: Invalid flag: -particleName //
// Error:
Error detected in e:...\consoledebug.cpp, line 51: (kFailure): Unexpected Internal Failure //
I had already added the parameter flag "-particleName" in to the syntax.
My software context is : Maya2009 x32, windowsXP SP2, VC2005
Here is my code, and you can download the project here.
Could you give me any suggestion? Thank you.
//------------------------ .h -----------------------------------
#ifndef _CONSOLE_DEBUG_
#define _CONSOLE_DEBUG_
#include
#include
#include
#include
#include
// test case:
// testcmd -particleName "aaa";
class ConsoleDebug : public MPxCommand
{
public:
ConsoleDebug();
virtual ~ConsoleDebug();
virtual MStatus doIt ( const MArgList& );
virtual bool isUndoable() const { return true; }
static void *creator() { return new ConsoleDebug; }
static MSyntax newSyntax();
static const MTypeId typeId;
static const MString typeName;
protected:
MStatus parseArgs(const MArgList& args);
MStatus onName();
bool fName;
MString mName;
};
#endif//#ifndef _CONSOLE_DEBUG_
//------------------------ .cpp -----------------------------------
#include "ConsoleDebug.h"
#include
#include
#include
#include
using namespace std;
//////////////////////////////////////////////////////////////////////////
void displayError(const MString& error);
#define PrintError(msg) { MString _m_output = "\nError detected in "; _m_output += __FILE__; _m_output += ", line "; _m_output += __LINE__; _m_output += ": "; _m_output += (msg); displayError(_m_output); }
#define IfMErrorWarn(x) { MStatus _m_s = (x); if (!_m_s) { PrintError(_m_s.errorString()); } }
#define _LogDebug(log) std::cout << log << std::endl;
//////////////////////////////////////////////////////////////////////////
#ifdef WIN32
#pragma comment(lib,"Foundation.lib")
#pragma comment(lib,"OpenMaya.lib")
#pragma comment(lib,"OpenMayaFx.lib")
#pragma comment(lib,"OpenMayaUi.lib")
#pragma comment(lib,"Image.lib")
#pragma comment(lib,"OpenMayaAnim.lib")
#endif
#ifdef WIN32
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
//////////////////////////////////////////////////////////////////////////
const char * kPARTICLE_NAME_S="-pname";
const char * kPARTICLE_NAME_L="-particleName";
const MTypeId ConsoleDebug::typeId(0xFFFFF356);
const MString ConsoleDebug::typeName("testcmd");
//////////////////////////////////////////////////////////////////////////
ConsoleDebug::ConsoleDebug(){}
//
ConsoleDebug::~ConsoleDebug(){}
//
MSyntax ConsoleDebug::newSyntax()
{
MSyntax syntax;
IfMErrorWarn(syntax.addFlag( kPARTICLE_NAME_S, kPARTICLE_NAME_L, MSyntax::kString));//----------------------------------line 41 !
return syntax;
}
//
MStatus ConsoleDebug::parseArgs(const MArgList& args)
{
MStatus status;
MArgDatabase argData(newSyntax(), args, &status);
IfMErrorWarn(status);//----------------------------------line 51 !
fName = argData.isFlagSet( kPARTICLE_NAME_L, &status );
IfMErrorWarn(status);
if( fName) {
IfMErrorWarn(argData.getFlagArgument(kPARTICLE_NAME_L, 0, mName));
}
_LogDebug("fName="<<fName);
return MStatus::kSuccess;
}
//
MStatus ConsoleDebug::doIt ( const MArgList &args )
{
IfMErrorWarn(parseArgs(args)) ;
if(fName){ IfMErrorWarn(onName()); }
return MS::kSuccess;
}
//
MStatus ConsoleDebug::onName()
{
MStatus stat = MS::kSuccess;
std::cout <<"name:"<< mName<<std::endl;
return MS::kSuccess;
}
///////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
EXPORT MStatus initializePlugin( MObject obj )
{
MStatus status;
MFnPlugin plugin( obj, "yaoyansi", "1.0", "Any");
status = plugin.registerCommand(
ConsoleDebug::typeName,
ConsoleDebug::creator,
ConsoleDebug::newSyntax);
IfMErrorWarn(status);
return status;
}
//
EXPORT MStatus uninitializePlugin( MObject obj)
{
MStatus status;
MFnPlugin plugin( obj );
status = plugin.deregisterCommand( ConsoleDebug::typeName );
IfMErrorWarn(status);
return status;
}
//
void displayError(const MString& error)
{
MGlobal::displayError(error);
std::cout<< "[ERR]:"<<error.asChar()<< std::endl;
}