MSyntax & MArgDatabase BUG ?


#1

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!


#2

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.

https://download.autodesk.com/us/maya/2010help/API/class_m_fn_plugin.html#40cc2cdd8b3a5751d66f88713051c4c2

Meaning, when you need to run it something like:

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