Manage Hotkeys through mel

Manage Hotkeys through mel

jerome.pourcel
Contributor Contributor
2,442 Views
6 Replies
Message 2 of 7

Manage Hotkeys through mel

jerome.pourcel
Contributor
Contributor

Hi,

 

Is it just me or the hotkey manager is a nightmare? It should be so simple... Whatever.

 

I'd like to load dynamically hotkeys through MEL at startup, so that they are shared with all my co-workers, regardless of maya's version, even if the "prefs" folder has been removed.

I'd like to import hotkeys at startup from a shared folder (versioned on GIT).

I've looked around if i could find out a solution (first of all, of course, in Maya documentation), but each time I thought I had the solution, it was a failure...

I've tried many mays without any result.

e.g.

  • write the userNamedCommands.mel and userRunTimeCommands.mel files in prefs/ at startup
  • writing userHotKeys_[setName].mel and[setName].mhk in prefs/hotkey/  at startup
  • load the hotkeySet
  • write again mel files when quitting Maya

But it doesn't work and I couldn't find the right way. 

It doesn't work even if i load manually the .mhk file in the hotkey editor. That how it looks like (with just one hotkey):

//runTimeCommand
runTimeCommand 
	-annotation "F4_UseFlatLights"
	-category "F4" -hotkeyCtx ""
	-commandLanguage "mel"
	-command ("JPL_DisplayUseFlatLight ();")
	F4_UseFlatLights;

//nameCommand
nameCommand
	-annotation "F4_UseFlatLightsNameCommand"
	-sourceType "mel"
	-command ("F4_UseFlatLights")
	F4_UseFlatLightsNameCommand;

//hotkey
hotkey -keyShortcut "0" -name ("F4_UseFlatLightsNameCommand");

I've got to admit that i don't really understand the mysterious mechanism of Maya's hotkeys managing...

What would be the wright way to dynamically load hotkeys? I think i don't need an actuel code but just the logical process.

I would reeeally appreciate a help on that...

 

Thanks

0 Likes
Accepted solutions (1)
2,443 Views
6 Replies
Replies (6)
Message 1 of 7

jerome.pourcel
Contributor
Contributor

Hi,

 

Somthing went wrong with my post, so i repost it, sorry if there's a double post...

 

I'd like to write hotkeys at startup unsing mel so that all my co-workers have the sames, whatever the version of Maya is used.

But, first of all, it should work manually, which is not the case...

I tried this :

  • Delete prefs to have a fresh start
  • Start Maya, creating a new preferences folder
  • Copy my .mhk file into /prefs/hotkeys/
  • Hotkey Editor --> impot this .mhk file (I don't have any error nor warning message)
  • The set is not in the set list...
  • Save and close (userNamedCommands.mel and userRunTimeCommands.mel seem ok)
  • Open again the hotKey Editor
  • Still no custom set appearing in the list but the commands written in the mhk file do appear... in the Maya Default set... and without shortcuts.
  • No "userHotKeys_[setName].mel" is created in /prefs/hotkeys/

My .mhk file looks like this (I kept here only one hk):

//runTimeCommand
runTimeCommand 
	-annotation "F4_UseFlatLights"
	-category "F4" -hotkeyCtx ""
	-commandLanguage "mel"
	-command ("JPL_DisplayUseFlatLight ();")
	F4_UseFlatLights;

//nameCommand
nameCommand
	-annotation "F4_UseFlatLightsNameCommand"
	-sourceType "mel"
	-command ("F4_UseFlatLights")
	F4_UseFlatLightsNameCommand;

//hotkey
hotkey -keyShortcut "0" -name ("F4_UseFlatLightsNameCommand");

I've tried and tried angain in many different ways through MEL or manually, whithout any result. I assume I do something wrong but i can't figure it out...

 

What would be the right way ?

0 Likes
Message 3 of 7

sean.heasley
Alumni
Alumni
Accepted solution

Hi @jerome.pourcel 

 

Setting it up to run at startup may not be possible as I believe most scripts need to have Maya open and running before they can be used.

 

What you could do is simply make a button that assigns the hotkeys so when you or your co-workers launch Maya you just need to press a button and it will map all of the hotkeys.

 

 

0 Likes
Message 4 of 7

jerome.pourcel
Contributor
Contributor

Thanks Sean!

 

I already thought about that kind of solution (but thought it wasn't a great idea. You've changed my mind). Now I have to do it 🙂

 

By the way, it's possible to run a script at startup with evalDeferred, evalDeffered -l or, if you wanna be sure, evalDeffered -lp, isn't it ?

I use that command to source all scripts in a specific folder, and to share my marking menus (much easier than sharing hotkeys...)

Yhanks again

0 Likes
Message 5 of 7

jerome.pourcel
Contributor
Contributor

Actually... It doesn't seem to work... I tried this :

global proc JPL_CopyHotKeysFiles ()
{
	string $destinationPrefsPath = (`internalVar -upd`);
	string $destinationHotkeysPath = ($destinationPrefsPath + "hotkeys/");
	string $sourcePath = (`internalVar -uad` + "scripts/hotkeys/");//where my hotkeys are stored (GITHub versioned)
	string $hotkeys [] = {"F4_Hotkeys.mhk","userHotkeys_F4_Hotkeys.mel","userNamedCommands.mel","userRunTimeCommands.mel"};

	sysFile -cp ($destinationHotkeysPath + $hotkeys [0]) ($sourcePath + $hotkeys [0]);
	sysFile -cp ($destinationHotkeysPath + $hotkeys [1]) ($sourcePath + $hotkeys [1]);
	sysFile -cp ($destinationPrefsPath + $hotkeys [2]) ($sourcePath + $hotkeys [2]);
	sysFile -cp ($destinationPrefsPath + $hotkeys [3]) ($sourcePath + $hotkeys [3]);
}

I launch this script whithin Maya, and everythings seems ok, the files are updated. But the hotkeys I added don't work and if I open the hotkeys Editor, the commands I added don't appear... Save and close, the files are back as before.

It seems to work only if I manually copy the file whithout Maya...

Did I miss something?

0 Likes
Message 6 of 7

jerome.pourcel
Contributor
Contributor

Ok, it does work now!

proc JPL_TransferFilesFromGIT ()
{
	string $destinationPrefsPath = (`internalVar -upd`);
	string $destinationHotkeysPath = (`internalVar -uhk`);
	string $sourcePath = (`internalVar -uad` + "scripts/hotkeys/");
	string $hotkeys [] = {"F4_Hotkeys.mhk","userHotkeys_F4_Hotkeys.mel","userNamedCommands.mel","userRunTimeCommands.mel"};

	sysFile -cp ($destinationHotkeysPath + $hotkeys [0]) ($sourcePath + $hotkeys [0]);
	sysFile -cp ($destinationHotkeysPath + $hotkeys [1]) ($sourcePath + $hotkeys [1]);
	sysFile -cp ($destinationPrefsPath + $hotkeys [2]) ($sourcePath + $hotkeys [2]);
	sysFile -cp ($destinationPrefsPath + $hotkeys [3]) ($sourcePath + $hotkeys [3]);
}

global proc JPL_CopyHotKeysFiles ()
{
	string $path = (`internalVar -uad` + "scripts/hotkeys/");

	JPL_TransferFilesFromGIT ();
	hotkeySet -e -cu "Maya_Default";
	hotkeySet -cu -src "F4_Hotkeys" "F4_HotkeysTMP";
	hotkeySet -e -del "F4_Hotkeys";
	catchQuiet (`hotkeySet -e -ip ($path + "F4_Hotkeys.mhk")`);
	hotkeySet -e -re "F4_Hotkeys" "F4_HotkeysTMP";
}

Maybe too much lines on the end, but it works, I don't touch it anymore ! 😄

Message 7 of 7

sean.heasley
Alumni
Alumni

Hi @jerome.pourcel 

 

Awesome! Glad you were able to figure it out and thanks for posting it here as well!

 

 

0 Likes