Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MEL Statements - HowTo execute more than 1 cmd under single IF

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
The-Digital-Shaman
214 Views, 3 Replies

MEL Statements - HowTo execute more than 1 cmd under single IF

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.

 

Labels (1)
3 REPLIES 3
Message 2 of 4

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!

 

Message 3 of 4

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; 
    }

 

Message 4 of 4

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.

Post to forums  

Autodesk Design & Make Report