If you are just using the native Maya UI, could you just make use of the 
postMenuCommand? It gets called when the menu is about to be shown, given you 
the opportunity to populate it any way you want. It would then just be a matter 
of packaging up the right data for each callback. Something like this?

###
import os
from functools import partial
import maya.cmds

def populate_menu(path, menuPath, *args, **kwargs):
    # resolve the paths children
    submenus = ['sub1', 'sub2']
    items = ['foo', 'biz', 'baz']
    
    for sub in submenus:
        submenu = cmds.menuItem(label=sub, parent=menuPath, subMenu=True)
        subpath = os.path.join(path, sub)
        cmds.menuItem(submenu, e=True, pmc=partial(populate_menu, subpath, 
submenu))
        
    for item in items:
        cmds.menuItem(label=item, parent=menuPath)

cmds.window( menuBar=True, width=200 )
pub_menu = cmds.menu( label='Publisher', tearOff=True )
cmds.menu(pub_menu, e=True, pmc=partial(populate_menu, '/Publisher', pub_menu))
cmds.showWindow()
###

The populate_menu() call would take the search path for you to use to find both 
child menus and leaf items. And you pass the menu path to use as a parent.




On Jul 2, 2013, at 9:29 PM, Simon Payne wrote:

> Hi guys,
> 
> I have an assets/shots browser for my 3D pipeline. It traverses 
> directories/database calls, by category etc. Obviously, as this is search 
> criterea, it is self updating. So if someone releases a new asset/shot or a 
> version of a model, rig, animation etc, it will come up in the UI no problem, 
> when you look into that shot/asset/category etc because it searches every 
> time you look there. But what I'd like to do for a good reason, is to have a 
> menu-based version, that is therefore free from a UI. So in my Publisher 
> menu, you'd go to the show>category>asset>model>version, or 
> show>shot>layout>crowd member>animation>version, etc etc.
> 
> So my question is, does anyone know if it is possible to trigger a command 
> (that would perform a search, and rebuild resulting submenus) when you click 
> an item in a maya menu? Obviously, the code to rebuild/edit a menu/submenu is 
> straight forward. But its triggering that code that is the key to a 
> menu-based asset/shot manager.
> 
> Thanks
> Simon
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to