Scripting marking menu including hotkey


#1

Hey, I seek the collective wisdom of these forums once again.

So I’m trying to script a marking menu from start to finish (python), including assigning a hotkey to it.

I’ve googled around a lot and there seems to be not much coverage on the subject. I’ve found a few posts that talked about it, but very vaguely and sometimes the examples in those posts didn’t work as well as advertised.

So far, I got this:


def createMarkingMenu_rigUtils():
    
    if mc.popupMenu('custom_rigUtils', ex = True): mc.deleteUI('custom_rigUtils')
    
    rigUtilsPopupMenu = mc.popupMenu('custom_rigUtils', b = 1, mm = True)
    mc.menuItem(l = 'select all controls', c = selectAllControls)
    mc.menuItem(l = 'select hand controls', c = selectHandControls)
    mc.setParent('..', m = True)
    
    fileName_savedMarkingMenu = mc.saveMenu(rigUtilsPopupMenu, 'menu_custom_rigUtils')
    print 'The rigUtils marking menu was saved.'
    
    # and delete, since this proc was solely to create that file
    if mc.popupMenu('custom_rigUtils', ex = True): mc.deleteUI('custom_rigUtils')

def hotkeyCommand_MM_rigUtils():
    
    if mc.popupMenu('custom_rigUtils', ex = True): mc.deleteUI('custom_rigUtils')
    mc.popupMenu('custom_rigUtils', b = 1, ctl = False, alt = False, sh = False, mm = True, aob = True, p = 'findPanelPopupParent')
    mel.eval('source "menu_custom_rigUtils"')

def createHotkey_MM_rigUtils():
    
    if not mc.runTimeCommand('build_MM_rigUtils_rtc', ex = True):
        mc.runTimeCommand('build_MM_rigUtils_rtc', ann = 'rigUtils MM hotkey', category = 'User Stuff', c = 'hotkeyCommand_MM_rigUtils')
    mc.nameCommand('build_MM_rigUtils_nc', ann = 'rigUtils MM hotkey nameCmd', c = 'build_MM_rigUtils_rtc')
    mc.hotkey(rn = 'MM_rigUtils_popDown', n = 'build_MM_rigUtils_nc', k = 'l')

Now when i run createMarkingMenu_rigUtils(), it most of the time works fine, but sometimes it throws me a

File “<maya console>”, line 5, in createMarkingMenu_rigUtils

RuntimeError: Object’s window not found.

(thats the line when it creates the popup menu)

  • so Im thinking that can be handled by creating a proxy window for the time being just so the popup menu has a parent, since im only using that proc to save the contents of the popup menu and then would delete that window anyway.

But more importantly. When it works, it shows up in the custom marking menus, but doesnt have a ‘assign to hotkey editor’ to it, so i have to do that manually. and the hotkey that i created via the proc doesnt work for it for some reason.

The idea here is so that i can distribute this script to artists, and it would create a new marking menu without any hassle.

Cheers to any soul willing to help me out here! :slight_smile:


#2

alright, got it.

if anyone is interested in seeing the code, lemme know.


#3

I would love to see the code. I’m trying to do the same thing.

Cheers!