Notes on the below info:
- The top section shows two different ways for authoring hotkey commands. I've only had success using
runTimeCommand
: using namedCommand
just doesn't seem to work. - When authoring a new
runTimeCommand
via code (as described below), it will immediately be available for usage in the Hotkey Editor. - When authoring a new hotkey via the
namedCommand
command (as described below), I've not had the best luck: When accessing the Hotkey Editor, it shows the hotkey as existing, but they key-combo I assigned to it isn't shown. When I reassign the key-combo, it says it's already assigned, but still won't work. Either I'm doing something wrong, or it's a bug.
To make a hotkey (all via code), you first must author the 'command' it will execute via either a
runTimeCommand
or
nameCommand
, then create the key binding via
hotkey
command.
Command Authoring
runTimeCommand
The
runtTimeCommand command will, from the docs: "Create a MEL command given the specified name. Once the command is created you can invoke it like any other MEL command."
Note that for some reason there are only mel docs for it, even though it is exposed in Python.
If coding the command, if the 'category' flag is set to "User" (and it probably should), the commands will be saved in this mel script:
\Documents\maya\<version>\prefs\userRunTimeCommands.mel
In the Hotkey Editor, when the user interactively creates a command in the 'User' category, they are saved via this method in the above mel script as well.
nameCommand
Note: I couldn't get this way to work. I'd recommend using the
runTimeCommand
solution above.
nameCommand is a command that from the docs "...creates a
nameCommand
object. Each
nameCommand
object can be connected to a hotkey."
When the user creates one of these from mel or Python, they are saved in this mel script:
\Documents\maya\<version>\prefs\userNamedCommands.mel
It should be noted that the command can accept either a mel or Python command to execute via it's
-sourceType
and
-command
flags. That being said, when I pass in Python commands, I get errors. However, if I define the
-sourceType
to be mel, then call to my Python code via the
python
mel command, the errors go away. Go figure.
Hotkey Creation
hotkey
The
hotkey command will, from the docs "...sets the single-key hotkeys for the entire application."
When the
user creates a hotkey in the Hotkey Editor, or via this command, they are stored in this mel script:
\Documents\maya\<version>\prefs\userHotkeys.mel
After the hotkey has been created, you'll need to call to the command separately to save it (via
autoSave=True
).