I use Autodesk Maya 2016 + Python.
I had a problem. I need to replace the functions of standard menu items and toolbars. For example, you must add the function to save a recording function. And because different people use different functionality, you have to change everything at once. Someone presses Ctrl+S
, others go to the menu File->Save
, and some press icon on the toolbar. In all areas it is necessary to replace the functionality. I understand that the problem boils down to in order to access the menus, toolbars and keyboard shortcuts. Next, find the associates item on the estate to know what function is now called. Then replace it with their cause and at the end of the function that invoked earlier in this menu.
File
and other)?Maya is based on QT. So just need to get the objects, and then have the standard means of QT can do everything.
How to do it?
All three ways of doing this call the runTimeCommand
named SaveScene
. Override that command and you have hijacked all of the three ways you describe. This is a bit tricky since the command is marked with the flag -default
which makes it impossible to change them on the fly. You can hook them where they are first defined. They are defined in the file:
Copy this file to your user profile maya script directory or studio script directry. These will get precedence of factory script due to resolution order. Do not overwrite the factory file. Then change -command
in the lines,
runTimeCommand -default true
-annotation (uiRes("m_defaultRunTimeCommands.kSaveSceneAnnot"))
-category ("File")
-command ("checkForUnknownNodes(); FileMenu_SaveItem")
SaveScene;
to something else. Best would be just to add a hook here.
Obviously, you can also change the button/menuitem and hotkey too. So what you do is run following mel (it's easier to do this in mel since the bulk of the commands are built that way, port to python or c++ if you must):
runTimeCommand
-annotation "Print the word \"Hello\""
-command ("print \"foo\"")
MySave;
nameCommand
-annotation "Print the word \"Hello\""
-command ("print \"foo\"")
MySaveNamed;
buildFileMenu();
menuItem -e -c "MySave" "MayaWindow|mainFileMenu|saveItem";
iconTextButton -e -c "MySave2" openSceneButton;
hotkey -keyShortcut "s" -ctl -name ("MySaveNamed");
Warning: The hotkey will be permanent in prefs, until you change it back or reset prefs.
Please note: There are at least two other ways user could save and you could not have full control of those even if you wanted to.