[MSyntax] addFlag does not work

67 views
Skip to first unread message

Rémi Deletrain

unread,
Oct 25, 2017, 6:52:12 AM10/25/17
to Python Programming for Autodesk Maya
Hi everyone,

I try to create au plugin with MPxCommand.

I have classic code found on MSyntax api class exemple. My code:
MSyntax SSDRCommands::newSyntax() {

MStatus status;
MSyntax syntax;

syntax.addFlag(kShortShapeName, kLongShapeName, MSyntax::kString);
CHECK_MSTATUS_AND_RETURN(status, syntax);
syntax.addFlag(kShortNumJoints, kLongNumJoints, MSyntax::kLong);
CHECK_MSTATUS_AND_RETURN(status, syntax);
syntax.addFlag(kShortMaxInfluences, kLongMaxInfluences, MSyntax::kLong);
CHECK_MSTATUS_AND_RETURN(status, syntax);
syntax.addFlag(kShortNumIterations, kLongNumIterations, MSyntax::kLong);
CHECK_MSTATUS_AND_RETURN(status, syntax);
syntax.addFlag(kShortStartTime, kLongStartTime, MSyntax::kDouble);
CHECK_MSTATUS_AND_RETURN(status, syntax);
syntax.addFlag(kShortEndTime, kLongEndTime, MSyntax::kDouble);
CHECK_MSTATUS_AND_RETURN(status, syntax);

syntax.useSelectionAsDefault(false);

return syntax;

}


MStatus return false, but I don't understand why...
Anyone have a solution ?

Justin Israel

unread,
Oct 25, 2017, 2:22:57 PM10/25/17
to python_in...@googlegroups.com
There is no point to using an MStatus and calls to CHECK_MSTATUS_AND_RETURN here. None of your function calls ever accept a status to ever change its state. So you are just checking the state of the default constructed MStatus every time. However, the default constructor for MStatus should initialize it to kSuccess which should make the check pass each time anyways. So I am not sure what you mean when you say it returns "false". It should just make it to the end of the function and return your MSyntax as expected. 



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4e85d611-7477-45c5-91bc-3c7e69b847b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rémi Deletrain

unread,
Oct 26, 2017, 3:34:00 AM10/26/17
to Python Programming for Autodesk Maya
This code it's a copy/past of maya exemple. It's the last test I do but doesn't work too.

I break on my code with this test:
status = syntax.addFlag(kShortShapeName, kLongShapeName, MSyntax::kString);
if (status != MStatus::kSucces){
   
MGlobal::displayError("ERROR: ...");
}

With this test I pass on the condition...

I try to make other plugin with the same code, just for have argument and that works... I don't understand...
I think make a copy/past of the test plugin on my plugin but I want to understand my problem..

Michael Boon

unread,
Oct 26, 2017, 7:04:59 PM10/26/17
to Python Programming for Autodesk Maya
I don't understand properly.
Are you saying that the code in your second post works correctly? The big difference between that and your first post is what Justin said - in your second post you set status.
status =syntax.addFlag(...
compared with the first post
syntax.addFlag(...
So in your first post, status is never set, and you are checking an ininitialized variable.

Rémi Deletrain

unread,
Oct 27, 2017, 3:00:32 AM10/27/17
to Python Programming for Autodesk Maya
In fact I tried a lot of things to try to run my plugin. The first post is the last test I did and it's a copy / paste of an example of the API. As Justin said with this code I do not check the return of the addFlag command. The second post is the code that allowed me to check and see the function addFlag is false. But as it is a false it does not work ... I did a test. A plugin that does nothing, I just add the flags and I look if it works in Maya. And it works ... So I do not understand why in my plugin it does not work and why the "neutral" plugin it works ...

Justin Israel

unread,
Oct 27, 2017, 3:17:38 AM10/27/17
to python_in...@googlegroups.com


On Fri, Oct 27, 2017, 8:00 PM Rémi Deletrain <remi.de...@gmail.com> wrote:
In fact I tried a lot of things to try to run my plugin. The first post is the last test I did and it's a copy / paste of an example of the API. As Justin said with this code I do not check the return of the addFlag command. The second post is the code that allowed me to check and see the function addFlag is false. But as it is a false it does not work ... I did a test. A plugin that does nothing, I just add the flags and I look if it works in Maya. And it works ... So I do not understand why in my plugin it does not work and why the "neutral" plugin it works ...

You might have to post a full example of your code that does not work. 


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

Rémi Deletrain

unread,
Nov 3, 2017, 3:32:44 AM11/3/17
to Python Programming for Autodesk Maya
Sorry for my late answer...

I think i found the problem but it's mean weird. I inversed longFlagName and shotFlagName in command "addFlag".
I do not know why he would crash on it. In any case I have my arguments and the command that works.

Michael Boon

unread,
Nov 7, 2017, 6:51:16 PM11/7/17
to Python Programming for Autodesk Maya
Glad to hear you figured it out.

I have never got MSyntax to work on the first attempt. It just seems to be finicky, and there's always some small thing that makes it fail.
Reply all
Reply to author
Forward
0 new messages