i'm writting a custom command in C++, but intending to call that from
maya in python.
i need to define a multiuse argument for it (array of strings).
i've got command up and running, but the problem is... MEL call works
fine, while Python
won't. my code is really based just on whatever is posted as a correct
example of reading
multi-use arguments (including the example in maya's API)
software: maya 2008, visual studio 2008.
i call command as:
MEL: ngTestCmd -s "persp" -s "top" (outputs "persp" and "top" correctly)
Python: cmds.ngTestCmd(s=["persp","top"]) (fails trying to print first
element)
i define command syntax as:
MSyntax syntax;
syntax.addFlag(TEST_FLAG,"strings",MSyntax::kString);
syntax.makeFlagMultiUse(TEST_FLAG);
syntax.enableQuery( false );
syntax.enableEdit( false );
return syntax;
i read args like this (CHECK_STATUS macro fires statusException if
status is not "success"):
try {
MStatus status;
MArgDatabase argDb(this->syntax(),args,&status);
CHECK_STATUS("failed to create arg db");
uint numUses = argDb.numberOfFlagUses(TEST_FLAG);
for (uint i=0;i<numUses;i++){
MArgList selList;
status = argDb.getFlagArgumentList(TEST_FLAG,i,selList);
CHECK_STATUS("failed to get sel list");
// asString fails when command call is made from python
MGlobal::displayInfo(selList.asString(0,&status));
CHECK_STATUS("failed to get string from sel list");
}
}
catch (StatusException e){
MGlobal::displayError(e.getStatus().errorString());
return e.getStatus();
}
in both python and MEL calls numberOfFlagUses return 2, which is
correct. however,
python calls always result in status check failure after selList.asString()
help! :)
--
viktoras
www.neglostyti.com
- Chris
it's not very good news after spending half a day trying to find out
what i was doing wrong.
is this a bug in maya 2008, or is it unresolved in 2010 as well?
mel.eval doesn't look like a best option. i guess i'll go with another
hacky solution and
allow passing parameter list in two ways:
python: cmds.myCommand(allParams="param1;param2;param3")
mel: myCommand -param "param1" -param "param2" -param "param3"
and split "allParams" into multiple ones if "param" is not present.
--
viktoras
www.neglostyti.com
i was also considering supplying those optional flags as maya's
selection sets, this would only require one identifier per flag.
--
viktoras
www.neglostyti.com