MSyntax & MArgDatabase BUG ?


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);
  	MString name;
  	if (argData.isFlagSet("-name"))
  		status = argData.getFlagArgument("-name", 0 , name);

then after compiling and loading in maya. I call :


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 :

Any idea why it is not working ???

Thx !


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!


I realize this is very late, but I figure any answer is better than nothing. I’ve seen this issue when you register the command using MFnPlugin.registerCommand and you forget to pass the syntax function you’re using. Otherwise, maya assumes you have no syntax flags in your command.

Meaning, when you need to run it something like:

MFnPlugin.registerCommand(“pluginName”, Test::creator, Test::newSyntax);