Hey Ævar, I'm not sure what the most user friendly way (and/or best way) for this is. I guess it totally depends on what you're trying to use it for. I had this code laying around (and have been using it from time to time). Quickly added some documentation to it.
from pymel.core.language import MelGlobals import maya.cmds as mc import maya.mel as mel # The file menu gMainFileMenu = MelGlobals.get('$gMainFileMenu') # Get the file menu's name command = mc.menu(gMainFileMenu, q=1, postMenuCommand=True) # Get the postMenuCommand mel.eval(command) # Call the postMenuCommand to force update defaultMenuItems = mc.menu(gMainFileMenu,q=1,ia=True) # Get the items in the list # I've also seen the following being called to force the file menu to be built mel.eval("buildFileMenu()") # If you want to add something to the file menu on Maya boot you could make an # userSetup.py file and add to the menu after Maya's boot sequence with executeDeffered, like: import maya.utils as utils utils.executeDeferred('foo()') # Though I think that since Maya 2010 you need to force Maya to build the # file menu to populate it with default items. This can be done with any # of the previously mentioned methods. # If you just want to add to the Main Menu bar, you can just use the gMainWindow variable: # Again, if you do this in userSetup make sure it's being executed deffered. :) gMainWindow = MelGlobals.get('gMainWindow') Does this help? I'm wondering what others have as general solutions for this! -Roy On Wednesday, July 10, 2013 9:53:30 PM UTC+2, Ævar Guðmundsson wrote: > Hi there > > > > I use this to get the Maya file menu and start populating it with various > things: > > > > import maya.cmds as cmds > > from pymel.core import menuItem,melGlobals > > from maya.mel import eval as melcommand > > gMainFileMenu=cmds.menu(melGlobals['$gMainFileMenu'],q=1,postMenuCommand=1) > > melcommand('string $fileMenuRefreshCmd = `menu -q -postMenuCommand > $gMainFileMenu`') > > melcommand('eval($fileMenuRefreshCmd)') > > defaultMenuItems=cmds.menu(melGlobals['$gMainFileMenu'],q=1,ia=True) > > > > It's embarrassing to admit, but in my defense it just works and I've been > copy pasting this example into my code for years. Finally figured to step > into modern days and figure out how to do this using a little bit friendlier > syntax... > > > > Problem being I have no idea how to do that and am still sat with this > Frankenstein code I wrote dragging along with me. > > > > Can someone please translate this for me into a more syntax and sharable > friendly way or point me at a good page to read up on this? > > > > Thanks in advance. > > -Ævar -- 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 python_inside_maya+unsubscr...@googlegroups.com. To post to this group, send email to python_inside_maya@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.