Edit/Override Maya Menu Commands

I’m just coming to the end of my asset management system and I wanted to override mayas open and save commands to run certain scripts.

I was thinking the best way of doing this was to edit the hot keys and the command the menu Item runs.

Problem is I dont know how to edit the command of an existing menu item, I can create a new one, but I’m not sure how to go about editing one.

As far as I can tell I can use the menuItem command with the edit flag, my issue is I don’t know how to get access to an existing menuitem in order to edit it, if that makes sense?

Is this the best method to use? Basically I am trying to reimplement save and open so they use my asset system rather than the default open and save commands.

Cheers.

Tom.

[QUOTE=supertom44;10447]I was thinking the best way of doing this was to edit the hot keys and the command the menu Item runs.
[/QUOTE]

The mechanism we use is leverage Maya’s script paths and it’s own code base.

We actually override the setProject function in the main menu. The mel file Maya uses is setProject.mel (surprise!), SO…

We took a copy of setProject. We added it to a path in our maya_script_path variable, and on startup we source it.

Then when Maya goes looking for setProject global, it uses our file instead.

If they update the core file, ours takes precedence until we can roll in the new changes they made and it leaves their core files alone (technically).

Another way would be to use callbacks (new, open, save, …) but not everything is covered, nor does it prevent the other code from triggering.

The menuItem route is an idea, but that feels like a lot more work vs reward to me.

HTH.

1 Like

you can override the functionality by creating a global procedure with the same name as maya’s. Its called something like FileMenuSave I think, so if you create a global proc called FileMenuSave and source it after maya has loaded, you’ll be able to control the save.

You can also find the script this function lives in and copy it to somewhere that will override where maya looks for this script. This way is probably more reliable, but it is more of a pain because upgrading to new versions of maya means you need to re-implement the edits you’ve made to the script.

Of course, people will still be able to run file -save from the command line

Cheers for the replies.

I did look into callbacks, also looked at sciptJobs and scriptNodes but none seemed correct.

I didn’t realise you could override the default function or procedure it calls, thats why I was trying to assign a different procedure to the menu item.

Whats the best way of executing some python code using this method, is it to wrap it in the mel command python like so:

global proc setProject ( string $newProject )
{
    python("print 'Set Project'");
}

Cheers, I really appreciate all the help.

yep, thats the way to go

I ended up going with a slightly different method, more what I was trying to do at first, mainly as I could do it all in python.

Here is what I ended up with:

command = """import sys 
if 'AssetManagementTool.Main.NoLogin' in sys.modules.keys():
    reload(AssetManagementTool.Main.NoLogin)
else:
    import AssetManagementTool.Main.NoLogin"""
    
mc.menuItem( "openProject",e=True, c=command)

The only downside is that when the hotkey is used it bypasses this, so I will have to add another line of code to edit the hotkey.

Ok so the last message can be ignored, I was having issues getting the hot keys to work so I just placed this in the userSetup.mel insead

global proc OpenScene()
{
    python("import sys
if 'AssetManagementTool.Main.NoLogin' in sys.modules.keys():reload(AssetManagementTool.Main.NoLogin)
else:import AssetManagementTool.Main.NoLogin");
}