Commands / Function syntax?

Commands / Function syntax?

FalconCrest
Advisor Advisor
1,104 Views
2 Replies
Message 1 of 3

Commands / Function syntax?

FalconCrest
Advisor
Advisor

Could someone please explain; as well when to use backquotes or backticks as some like to refer to them as ?

 

MEL allows you to type commands in command syntax (similar to UNIX shell commands) and function syntax.  In command syntax you can leave off quotation marks around single-word strings and separate arguments with spaces instead of commas. 

 

 

setAttr ("mySphere1.translateX", 10); // Function Syntax
setAttr mySphere1.translateX 10; // Command Syntax 

Function syntax automatically returns a value.  To get a return value using command syntax, you must enclose the command in backquotes.

 

$a = getAttr ("mySphere.translateX"); // Function syntax
$b = `getAttr mySphere.translateY`; //Command syntax 

 

0 Likes
Accepted solutions (1)
1,105 Views
2 Replies
Replies (2)
Message 2 of 3

tony.su
Autodesk Support
Autodesk Support
Accepted solution

http://help.autodesk.com/view/MAYAUL/2016/ENU/?guid=GUID-72889B4F-0D06-43C4-A70E-0E91FDA03BD0

 

To execute a command or procedure and get the return value you could use the eval, ``, or ( ) syntax as the following examples illustrate.

 

$transforms = eval("ls -type transform");

$transforms = `ls -type transform`;

$transforms = ls("-type", "transform");

 

 

eval

  1. Allows for delayed evaluation. Normally when a script is executed, if a command is not defined, Maya will still try to execute it.

    For example, if you try to execute a script that first loads a plug-in and then immediately executes it, the script will fail when the plug-in command is executed. This is because Maya initially evaluates the script to check for commands that it does not know. However, if the plug-in command is executed using the eval syntax then the script will not fail.

  2. Can embed commands. For example: eval("sphere; cone; ls");
  3. Entire command, including its arguments, must be a single string. For example: eval("ls -type transform");

backquotes

  1. Immediate evaluation.
  2. Can not embed commands.
  3. Do not need to put string arguments in quotes. For example: string $trans2[] = `ls -type transform`;
  4. Can not use this syntax as a stand-alone command because it’s intended for assigning the result of one command or building another command. For example, you can not do the following: `ls -type transform`;

( )

  1. Immediate evaluation.
  2. Can not embed commands.
  3. Must put string arguments in quotes. For example, if $faces represents the number of faces in an object, you might use ( ) to build a string to print out.

print("This object has " + $faces + " faces \n");



Tony Su
Product Support
0 Likes
Message 3 of 3

FalconCrest
Advisor
Advisor
Ah it's in the Docs 😉
0 Likes