Avatar
Jun 08, 2011
Post id: 308119 Report Item

Hi~~ Am using MSyntax and MArgDatabase to make my command plugin support the query and edit mode.
But in my design, I have a flag call -init ,which should have a stringArray as a argument. the stringArray is just an array of folder name, not Maya object names or something like that.

It seems that MArgDatabase doesn't support  MStringArray as an argument except they are valid maya objects.

Is that a way to support a MStringArray arg type ,meanwhile the flags got query & edit mode ?

Currently I have to define the flag argument as a MString and split the MString to MStringArray with a special char in doit function.

Thanks beforehand :)
 

Avatar2
Jun 08, 2011
Post id: 308126 Report Item

Theres definitely no way to pass an array variable as argument to a command, unfortunately. However you can make a argument "multi use", means that you would handover the different strings this way:
cmdName -init "string1" -init "string2"...
Ironically you would need to construct the whole command inside mel as string and then execute it via "eval", so it isnt much better than cutting your single string argument inside the API afterwards. BUT there is a little hacky solution, you can write a MEL command inside the API and use the MGlobal::executeCommand() to capture the result. In MEL declare the string array with initial values as global:

global string $initArray[] = {"path1","path2"};

and inside the API:

MStringArray result;
MString cmdStr = "proc string[] returnArray(){ global string $initArray[]; return $initArray;}; returnArray()";
MGlobal::executeCommand(cmdStr, result);

// not tested this, but should work

Dashboard_avatar
Jun 09, 2011
Post id: 308132 Report Item

Its possible to pass an array to a command, but not when using Msyntax and MArgDatabase. In those cases you need to parse all the stuff yourself. When you parse yourself you can implement querry and edit again its up to you.

>> Theres definitely no way to pass an array variable as argument to a command

Oh yeah its definitely possible to do this*. Its just that the classes built for syntax wont work. Incidenttaly whenever you see a mel command that does this its missing help command listing, because help is tied to the arg database. So its a tradeoff help or arrays. The other unfortunate side effect is that commands like this may or may not work in python. Offcourse the last thing maya passes is allways an array, anyway this a pretty annoying feature of the mel structure. Offcourse all these multiuses are arrays in python!

So no at the end of the day its not a entirely good solution even if you CAN do it, just not properly.


* or atleast it used to be possible to do, i really havent tested in long time. However i dont see them having done anything to ths functionality so...

Avatar
Jun 09, 2011
Post id: 308134 Report Item

Hmm.. OK,
I think I shall still split the MString to MStringArray inside API..  But thanks anyway! I have learned something :)