Maya 2016 - Hotkeys mel script desn't work anymore

Hello.
This works fine in Maya 2015 and looking in the help files, there seems nothing has changed, but I can’t get the following to work.

//Outliner Toggle
//===============================================
global proc outlinerToggle(){

//If window doesn't exist, create it
if (!`window -q -ex outlinerPanel1Window`)
	{
	OutlinerWindow;
	}

//If it does exist, toggle to minimize it or toggle to show it
else if (`window -q -ex outlinerPanel1Window` == 1){
		if (`window -q -i outlinerPanel1Window` == 1)
			{
			window -edit -i 0 outlinerPanel1Window;
			}
			
		else if (!`window -q -i outlinerPanel1Window`)
			{
			window -edit -i 1 outlinerPanel1Window;
			}
	}
}
$hotKey = `nameCommand
	 -annotation "Outliner"
    	 -command "outlinerToggle"`;
	hotkey -alt -k "2" -name $hotKey;

Not sure if this is relevant or not, but we have a hotkey-assigning script that stopped working in 2016. Except that it does work if you set at least one hotkey through Maya’s Hotkey Editor first. I am still looking into figuring out how to get the script to work if the user hasn’t set any hotkeys.

looks like autodesk got rid of “userHotkeys.mel” that is normally stored in My Documents/Maya/<version>/prefs

in 2016, there is a new subfolder in prefs called “hotkeys” and in that folder is where the shortcuts are stored. I assume they did this to support multiple configurations…

You are correct about the multiple configurations. Maya 2016 calls them hotkey sets. Maya has a default hotkey set, but it is locked and cannot be edited. So a different hotkey set must be active in order for assigning hotkeys to work.

You can check for the default hotkey set like this:

if cmds.hotkeySet(q=True, current=True) == "Maya_Default":

Note that the “hotkeySet” command is new in Maya 2016, so if you need your script to work in older versions, too, you will have to do a version check in the code.

Missed to check up on this thread.
Thank you very much. So what does this mean precisely? All I have to do is create a new hotkey set and add to that?

Thanks guys

Yes, that is correct. If this script is just for personal use, the easiest thing to do is open the Hotkey Editor and set one custom hotkey. That will automatically create a new hotkey set. Then when you run your script that assigns the hotkey, it should work.

If the script is something you intend to distribute to users, you will have to be a bit more robust, and check whether they have a hotkey set as part of the hotkey-setting script. So if you query the current hotkey set and it is “Maya_Default”, then you need to either create a new hotkey set or switch to a different existing hotkey set.

Tip on setting the new hotkey set:

# This command will set the current hotkey set.
#  It will throw an error if "myExampleHotkeySetName" does not exist.
cmds.hotkeyset("myExampleHotkeySetName", edit=True, current=True)

# This command will create a new hotkey set and make it the current one.
# It will throw an error if the "myExampleHotkeySetName" already exists.
cmds.hotkeyset("myExampleHotkeySetName", current=True)

Thanks! It worked great, but for my custom procedures I first had to create a new runtime command and paste my scriptname in the command box. I’ll do a version control and add this to my hotkeys script file after the declarations. No big deal, but what does it mean to create a runtime command? You never had to do this before.
Best regards/ Dag