Saturday, January 31, 2009

[Maya] Using MSyntax and MArgDatabase to handle the input parameters

Function:

Based on the previous code, implement the same function as before: create a bunch of cylinders along the selected curve.

 

Main Code:

Initialise the flags:

const char *numberFlag="-n", *numberLongFlag="-nmuber";
const char *radiusFlag="-r", *radiusLongFlag="-radius";
const char *heightFlag="-h", *heightLongFlag="-height";


doIt function:



MStatus Posts1Cmd::doIt(const MArgList &args)
{
int nPosts=5;
double radius=0.5;
double height=5.0;

MArgDatabase argData(syntax(),args);

if(argData.isFlagSet(numberFlag))
argData.getFlagArgument(numberFlag,0,nPosts);

if(argData.isFlagSet(radiusFlag))
argData.getFlagArgument(radiusFlag,0,radius);

if(argData.isFlagSet(heightFlag))
argData.getFlagArgument(heightFlag,0,height);


...



MSyntax function:



MSyntax Posts1Cmd::newSyntax()
{
MSyntax syntax;
syntax.addFlag(numberFlag,numberLongFlag,MSyntax::kLong);
syntax.addFlag(radiusFlag,radiusLongFlag,MSyntax::kDouble);
syntax.addFlag(heightFlag,heightLongFlag,MSyntax::kDouble);
return syntax;
}



static MSyntax newSyntax();


Modification of initializations function:



stat=pluginFn.registerCommand("posts1", 


Posts1Cmd::creator, 


Posts1Cmd::newSyntax);

No comments:

Post a Comment

Google+