Hi there,
I have a question regarding basics of how statements' syntax works in MEL.
I have a working script which cycles through Move, Rotate and Scale tools.
I would like to upgrade the code by adding more commands to be executed under each IF statement.
Working Code:
string $currentTool = `currentCtx`;
if ($currentTool == "moveSuperContext")
setToolTo $gScale;
else if ($currentTool == "scaleSuperContext")
setToolTo $gRotate;
else
setToolTo $gMove; tumbleCtx -e -autoSetPivot true tumbleContext; manipMoveContext -e -mode 2 Move; manipRotateContext -e -mode 2 Rotate; manipScaleContext -e -mode 2 Scale;
What I tried to do, but doesn't work:
string $currentTool = `currentCtx`;
if ($currentTool == "moveSuperContext")
setToolTo $gScale; manipScaleContext -e -mode 2 Scale;
else if ($currentTool == "scaleSuperContext")
setToolTo $gRotate; manipRotateContext -e -mode 2 Rotate;
else
setToolTo $gMove; tumbleCtx -e -autoSetPivot true tumbleContext; manipMoveContext -e -mode 2 Move;
Thanks for advising what would be a good way around it.
Solved! Go to Solution.
Solved by Kahylan. Go to Solution.
I'm acutally quite surprised the top script works, as MEL synthax usually needs curly brackets {} to indicate the start and end of condition statements. This is how you would write your second script:
string $currentTool = `currentCtx`;
if ($currentTool == "moveSuperContext"){
setToolTo $gScale;
manipScaleContext -e -mode 2 Scale;
}
else if ($currentTool == "scaleSuperContext"){
setToolTo $gRotate;
manipRotateContext -e -mode 2 Rotate;
}
else{
setToolTo $gMove; tumbleCtx -e -autoSetPivot true tumbleContext;
manipMoveContext -e -mode 2 Move;
}
I hope it helps!
You only need to scope with Curly Braces if you need more than one line of code.
so the following works just fine:
if ($currentTool == "moveSuperContext")
setToolTo $gScale;
else
print ("this is fine\n");
but for cleanliness, and more human readable I would indent the curly braces : ( even though mel doesn't respect white space)
string $currentTool = `currentCtx`;
if ($currentTool == "moveSuperContext")
{
setToolTo $gScale;
manipScaleContext -e -mode 2 Scale;
}
else if ($currentTool == "scaleSuperContext")
{
setToolTo $gRotate;
manipRotateContext -e -mode 2 Rotate;
}
else
{
setToolTo $gMove; tumbleCtx -e -autoSetPivot true tumbleContext;
manipMoveContext -e -mode 2 Move;
}
Thanks guys!
Curly brackets then.
Btw, there is a bit of inconsistency in Maya and mode 2 for Rotate is Gimbal, not World Axis, like it is for Move and Scale. Mode 1 is World Axis for Rotate. ^^
Can't find what you're looking for? Ask the community or share your knowledge.