Assign a MEL script to a hotkey

 
 
 

To associate a MEL script with a hotkey, you must first add the script to the list of available hotkey commands, then assign a hotkey to the command you created.

  1. Select Window > Settings/Preferences > Hotkey Editor.
  2. Commands are grouped into categories. Click the category name in the Categories list you want to put your script in.
  3. In the command area at the bottom of the hotkey editor, click New.
  4. Type a Name and Description for the new command.
  5. In the Command text box, type the MEL commands you want the hotkey to run.
  6. Click Accept.
  7. Type a key name in the Key text box and turn on any modifiers you want on the hotkey.

    For example, type m in the text box and turn on the Alt setting to assign the marking menu to + m.

    As you edit these settings, Maya shows the command currently assigned to the hotkey, if any. Only assign the hotkey if you don’t mind overriding this command.

  8. Set the Direction option. If you select Press, Maya runs the command when you press the key down. If you select Release, Maya runs the command when you let the key up.

    The distinction between Press and Release can be important, for example when you assign a hotkey to a snapping mode. You want to assign the command to turns the snapping mode on to the key press, and the command that turns the snapping mode off to the key release.

  9. Click Assign.

    If the hotkey you set already has a command assigned, Maya asks if you want to override it.

Example MEL scripts

You can use the following MEL scripts to create toggles for x-ray and wire/shaded modes.

Script 1:

/MEL to toggle xray mode on/off
//map to a hotkey
//get the current panel as xray mode works per panel
$currentPanel = `getPanel -withFocus`;
//get the state of xray mode (either on or off)
$state = `modelEditor -q -xray $currentPanel`;
//set it to the opposite state
modelEditor -edit -xray (!$state) $currentPanel;

Script 2:

//MEL to toggle cameras and image planes on/off
//map to a hotkey
$currentPanel = `getPanel -withFocus`;
$state = `modelEditor -q -cameras $currentPanel`;
modelEditor -edit -cameras (!$state) $currentPanel; 

Related topics

Creative Commons License Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License