pymel.core.windows.saveMenu

static windows.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. 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

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

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

pm.menuItem( rp='N', l='Up' )
# Result: ui.SubMenuItem('window1|columnLayout11|frameLayout11|popupMenu60|menuItem377') #
pm.menuItem( rp='S', l='Down' )
# Result: ui.SubMenuItem('window1|columnLayout11|frameLayout11|popupMenu60|menuItem378') #
pm.menuItem( rp='E', l='Right' )
# Result: ui.SubMenuItem('window1|columnLayout11|frameLayout11|popupMenu60|menuItem379') #
pm.menuItem( rp='W', l='Left' )
# Result: ui.SubMenuItem('window1|columnLayout11|frameLayout11|popupMenu60|menuItem380') #
pm.menuItem( label='Warm', sm=True )
# Result: ui.SubMenuItem('window1|columnLayout11|frameLayout11|popupMenu60|menuItem381') #
pm.menuItem( l='Red' )
# Result: ui.SubMenuItem('window1|columnLayout11|frameLayout11|popupMenu60|menuItem381|menuItem382') #
pm.menuItem( l='Orange' )
# Result: ui.SubMenuItem('window1|columnLayout11|frameLayout11|popupMenu60|menuItem381|menuItem383') #
pm.menuItem( l='Yellow' )
# Result: ui.SubMenuItem('window1|columnLayout11|frameLayout11|popupMenu60|menuItem381|menuItem384') #
pm.setParent( '..', m=True )
# Result: u'window1|columnLayout11|frameLayout11|popupMenu60' #
pm.menuItem( label='Cold', sm=True )
# Result: ui.SubMenuItem('window1|columnLayout11|frameLayout11|popupMenu60|menuItem385') #
pm.menuItem( l='Green' )
# Result: ui.SubMenuItem('window1|columnLayout11|frameLayout11|popupMenu60|menuItem385|menuItem386') #
pm.menuItem( l='Blue' )
# Result: ui.SubMenuItem('window1|columnLayout11|frameLayout11|popupMenu60|menuItem385|menuItem387') #
pm.menuItem( l='Indigo' )
# Result: ui.SubMenuItem('window1|columnLayout11|frameLayout11|popupMenu60|menuItem385|menuItem388') #
pm.menuItem( l='Violet' )
# Result: ui.SubMenuItem('window1|columnLayout11|frameLayout11|popupMenu60|menuItem385|menuItem389') #
pm.setParent( '..', m=True )
# Result: u'window1|columnLayout11|frameLayout11|popupMenu60' #
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