pymel.core.windows.saveMenu

saveMenu(*args, **kwargs)

This command is used for saving the contents of a menu, so that another instance of the menu may be recreated later. The command writes out a file which, when run as a script, will rebuild the menuItems contained in the original menu. Note that the fileName is relative to the user’s marking menu preference directory. Note that this command is used solely by the Marking Menu Editor and is not intended to be used for general purposes. Note that this command doesn’t work well with controls that have mixed mel and python command callbacks. Also, because it saves the menu state to a mel file, it does not work with callbacks that are python callable objects. The first argument is the name of the manu to save, the second one is the name of the file.

Derived from mel command maya.cmds.saveMenu

Example:

import pymel.core as pm

import maya.cmds as cmds

# Create a window with two frames.
#
win = pm.window(title='saveMenu Example')
pm.columnLayout()
# Result: ui.ColumnLayout('window1|columnLayout78') #
frame1 = pm.frameLayout( h=90, l='Original Menu (LMB)' )
pm.text( l='(click here)' )
# Result: ui.Text('window1|columnLayout78|frameLayout20|text7') #
pm.setParent( '..' )
# Result: u'window1|columnLayout78' #
frame2 = pm.frameLayout( h=90, l='Copy of Original (LMB)' )
pm.text( l='(click here)' )
# Result: ui.Text('window1|columnLayout78|frameLayout21|text8') #
pm.setParent( '..' )
# Result: u'window1|columnLayout78' #

# Create a menu.
#
menu1 = pm.popupMenu( parent=frame1, b=1, mm=True )

pm.menuItem( rp='N', l='Up' )
# Result: ui.CommandMenuItem('window1|columnLayout78|frameLayout20|popupMenu88|menuItem891') #
pm.menuItem( rp='S', l='Down' )
# Result: ui.CommandMenuItem('window1|columnLayout78|frameLayout20|popupMenu88|menuItem892') #
pm.menuItem( rp='E', l='Right' )
# Result: ui.CommandMenuItem('window1|columnLayout78|frameLayout20|popupMenu88|menuItem893') #
pm.menuItem( rp='W', l='Left' )
# Result: ui.CommandMenuItem('window1|columnLayout78|frameLayout20|popupMenu88|menuItem894') #
pm.menuItem( label='Warm', sm=True )
# Result: ui.CommandMenuItem('window1|columnLayout78|frameLayout20|popupMenu88|menuItem895') #
pm.menuItem( l='Red' )
# Result: ui.CommandMenuItem('window1|columnLayout78|frameLayout20|popupMenu88|menuItem895|menuItem896') #
pm.menuItem( l='Orange' )
# Result: ui.CommandMenuItem('window1|columnLayout78|frameLayout20|popupMenu88|menuItem895|menuItem897') #
pm.menuItem( l='Yellow' )
# Result: ui.CommandMenuItem('window1|columnLayout78|frameLayout20|popupMenu88|menuItem895|menuItem898') #
pm.setParent( '..', m=True )
# Result: u'window1|columnLayout78|frameLayout20|popupMenu88' #
pm.menuItem( label='Cold', sm=True )
# Result: ui.CommandMenuItem('window1|columnLayout78|frameLayout20|popupMenu88|menuItem899') #
pm.menuItem( l='Green' )
# Result: ui.CommandMenuItem('window1|columnLayout78|frameLayout20|popupMenu88|menuItem899|menuItem900') #
pm.menuItem( l='Blue' )
# Result: ui.CommandMenuItem('window1|columnLayout78|frameLayout20|popupMenu88|menuItem899|menuItem901') #
pm.menuItem( l='Indigo' )
# Result: ui.CommandMenuItem('window1|columnLayout78|frameLayout20|popupMenu88|menuItem899|menuItem902') #
pm.menuItem( l='Violet' )
# Result: ui.CommandMenuItem('window1|columnLayout78|frameLayout20|popupMenu88|menuItem899|menuItem903') #
pm.setParent( '..', m=True )
# Result: u'window1|columnLayout78|frameLayout20|popupMenu88' #
pm.setParent( '..', m=True )
# Result: u'' #

# Save the menu to a file.
#
result = pm.saveMenu(menu1, 'menu_example')

# Use the file to rebuild another instance of the menu.
#
menu1 = pm.popupMenu( parent=frame2, b=1, mm=True )
maya.mel.eval( 'source \"' + pm.internalVar(userMarkingMenuDir=True) + 'menu_example.mel\"' )
# Result: u'' #

# Finish up.
print ("The menu was saved in [" + pm.internalVar(userMarkingMenuDir=True) + result + "]\n" )
pm.showWindow( win )

Previous topic

pymel.core.windows.saveAllShelves

Next topic

pymel.core.windows.savePrefObjects

Core

Core Modules

Other Modules

This Page