Maya mel scripts mel maya language
What’s on this Page
What is a MEL file?
A file with .mel (Maya Embedded Language) extension is a scripting language that is used by Autodesk Maya to create graphical interfaces. It lets you automate the creation of graphical elements using executable scripts in addition to Maya’s graphical interface. MEL empowers you to create graphical interfaces without learning programming. This is achieved by creating Macros and custom actions that speed up repetitive tasks. These procedures and scripts let you create custom modelling, animations, dynamics and tasks rendering. Autodesk Maya 2020 can be used to open and view contents of an EML file.
MEL File Format — More Information
A programmer’s reference manual is available for developers on Maya’s documentation section. MEL is based on shell scripting commands, similar to UINX, to achieve things. The scripting based commands makes it irrelevant to conventional and object oriented programming (OOP), resulting in no usage of data structures, calling functions, or using OOP as in other languages.
Some key points about MEL are as follow.
Comments — Every statement in MEL must end with a semi-colon (;), even at the end of a block.
Returning Values — Stating an expression that returns a value does not automatically print the value in MEL. Instead it causes an error.
3 + 5; // Error: 3 + 5; // // Error: Syntax error // print(3+5); 8
Commands for Create, Edit and Delete — The same command is used to create things, edit things or query information about existing things. However, a flag controls what (create, edit, or query) the command does.
// Create a sphere named "mySphere" with radius 5 sphere -radius 5 -name "mySphere"; // Edit the radius of mySphere sphere -edit -radius "mySphere"; // Print the radius of mySphere sphere -query -radius
Return Value from Function — 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
References
See Also
- KT File Format
- VB — Visual Basic Code File
- VBPROJ
- VCXPROJ
- NUT — Squirrel Language File
Maya mel scripts mel maya language
Maya offers two different languages with which to create custom functionality via scripting—both Maya Embedded Language (MEL) scripts and Python. In practice, you’ll only want to use one, and of the two, Python offers a much better and more flexible experience.
However, it is not uncommon to have legacy scripts that were written back before Maya added Python functionality. While the «right» solution would be to rewrite the scripts using Python, there’s not always enough time to do so. In those cases, it can sometimes be helpful to be able to call out to legacy, MEL-based functionality from within your Python scripts.
Getting ready
Although Python is definitely the better way to create new functionality, it may sometimes be the case that you have older scripts that were written in MEL that you would like to incorporate.
The best option is to rewrite the script in Python, but if the script is complex or you don’t have time, it may be easier to just invoke the MEL functionality from within a Python script. This way, you can incorporate legacy functionality without completely reinventing the wheel.
How to do it.
For this recipe, you’ll need the MEL script. If you don’t have one handy, open up a new file and enter the following:
global proc myMELScript()
Save this as myMELScript.mel in your maya/scripts directory. Although we won’t be going into the details of MEL, do note that the file has the same name as the function that we’re defining. Most MEL scripts will follow that convention. Also note the inclusion of semicolons after the end of each line. Although Python doesn’t require them, MEL (and many other languages) does.
Once you have that, create a new file and name it runMEL.py . Enter the following:
import maya.cmds as cmds import maya.mel as mel def runMEL(): print("Running MEL from Python") mel.eval("source myMELScript;") mel.eval("myMELScript;") runMEL()
Save the script and run it with:
import runMEL
Because the last line of our script invokes the runMEL command, it will automatically take effect. You should see a new cube, as well as the following output in the Script Editor:
Running MEL from Python Hello from MEL!
How it works.
In this example, we imported both maya.cmds and maya.mel. The maya.mel library provides support to interface Python with MEL, with one of its most useful commands being the eval function, which takes an arbitrary string and attempts to run it as an MEL command. In the earlier example, we do that twice, with the first command being:
source myMEL;
The source command does the same thing as reload, in that it ensures that Maya will reread the entire source file, rather than rerunning a potentially outdated version. This shouldn’t matter because it’s only necessary if you’re making changes to the MEL script (and hopefully you’re not doing that, use Python instead!) but it’s a good thing to include just in case.
Once we’ve done this, we actually run the MEL script with:
It needs a human touch
Complete the task and we’ll get you right back into Fiverr.
Loading challenge
Quick fixes
- Disable any browser extensions that could be interfering with the website. This includes Ad blockers, privacy extensions, or VPNs that may modify web traffic.
- Clear your browser’s cache and cookies. Outdated or corrupt cache data can cause issues with how the webpage loads and operates.
- Make sure Javascript is enabled in your browser and update your browser to the latest version.
ERRCODE PXCR10002539
- uuid: d7dcca36-f37d-11ee-91a3-8affa85778e6
- ip: 95.214.216.211
Maya mel scripts mel maya language
Mel Script — The Basics
The entire user interface of Maya is driven by the Maya Embedded Language (mel for short). To begin with, open with script editor by clicking on the button in the bottom right hand corner of Maya.
The Script Editor
The script editor is the way in Maya that is available to edit and run mel scripts. The top pane of the editor is a results window where output from your scripts will displayed, or compilation errors. The bottom pane is where you edit your scripts.
In the bottom pane, type.
sphere ;
. and then press the little enter key (or control+enter if you are on a laptop). That should have executed the sphere command to create you a NURBS sphere within the Maya Scene.
In the script editor you have to use the little enter key to execute scripts, the large enter key is a newline needed when using a text editor. You may have noticed that after executing the script, the contents of the script editor vanished. Well, this is slightly annoying since you may still be in the process of working on the script.
To avoid this, simply highlight the lines of code to execute (ctrl+a is good for this) and then press the little enter key. The script will be executed as before however the code will remain in the script editor for further editing.
Useful Script Editor Menu Options
On the file menu we can open a file for editing, source (execute) a script, or save the current script either to the shelf or to a file.
On the edit menu we have the standard edit options you’d expect, but you also have 3 options at the bottom to clear the history (top pane), clear the input (bottom pane) or simply clear both.
On the script menu, there are two settings you’ll be wanting to turn on (trust me, you will). They are, «Show Line Numbers» and «Show Stack Trace». The first option will print the line number that a compilation error occurred on; the second will print some info about where the script went wrong at runtime. Without these two options on, debugging scripts is almost impossible.
Some people may have assumed that turning on the line numbers would give you line numbers down the side of the script editor. No such luck i’m afraid. The best method I can suggest is to work in an external text editor such as kate(linux) or textpad(Win32) to do your editing and save the script to the hard drive. By using source script from the file menu you can run the script (or alternatively use the source command).
Update: Maya 8 has now added line numbers to the script editor. If you use the Ctrl+Shift+L shortcut, you can now get two sets of line numbers if you really want. The latter set of line numbers may actually be more useful since it actually handles the case of selecting text and executing.
Comments
Within your scripts, it is useful to write small reminders, or comments to describe what the code is doing. // indicates that the text following it until the end of the line is a comment and not part of the code.
// print some text to the results window. \n indicates a newline print( "hello world\n" );
Random Script Editor Shortcuts
There are a few useful hotkey shortcuts for the mel script editor within Maya, it’s just that people don’t seem to know they exist!
ctrl + shift + '>' - Increase font size ctrl + shift + ' - Decrease font size ctrl + shift + '=' - Toggle font size ctrl + shift + 'L' - line numbers for selected text (press a few times) ctrl + 'E' - Aligns text to the center. ctrl + 'L' - Aligns text to the left. ctrl + 'R' - Aligns text to the right. ctrl + '1', or ctrl + '2', or ctrl + '5' - change font spacing ctrl + return - executes the current script. ctrl + backspace - delete a word. ctrl + left cursor - skip back a word ctrl + right cursor - skip forward a word ctrl + return - executes the current script (useful for laptops!). ctrl + Middle Mouse Wheel - use scrolling to control font size ctrl + shift + 'a' - Toggles selected text between lower & upper case ctrl + shift + 'm' - Execute selected code then deletes it