Hi community !
I am trying to create a c++ command and I have a problem
MSyntax Test::syntaxCreator()
{
MSyntax syntax;
syntax.addFlag("-na", "-name", MSyntax::kString);
syntax.addFlag("-t", "-test", MSyntax::kString);
return syntax;
}
MStatus Test::doIt(const MArgList& args)
{
// Collect data
MStatus status;
MArgDatabase argData(syntax(), args, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
MString name;
if (argData.isFlagSet("-name"))
{
status = argData.getFlagArgument("-name", 0 , name);
CHECK_MSTATUS_AND_RETURN_IT(status);
}
then after compiling and loading in maya. I call :
cmds.myCommand(name="testName")
And then Maya crashes ! I found out that it crashes on this line :
MArgDatabase argData(syntax(), args, &status);
So I replaced by :
MArgDatabase argData(Test::syntaxCreator(), args, &status);
because it returns the MSyntax. Now it doesn t crash anymore but it’s still not working. It doesn’t save the name in the MString, it doesn’t even go inside the loop…
I made this code from this example :
http://download.autodesk.com/us/maya/2011help/API/user_msg_cmd_8cpp-example.html#_a7
Any idea why it is not working ???
Thx !
EDIT:
Okay after further investigation I found out that it works but not with the first flag declared… so in my previous example, if I try with name it won’t work but if I try with test, it will …
super weird!