Go to: Synopsis. Return value. Python examples.
saveMenu(
string string
)
Note: Strings representing object names and arguments must be separated by commas. This is not depicted in the synopsis.
saveMenu is undoable, NOT queryable, and NOT editable.
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.string | The name of the saved file. |
import maya.cmds as cmds # Create a window with two frames. # win = cmds.window(title='saveMenu Example') cmds.columnLayout() frame1 = cmds.frameLayout( h=90, l='Original Menu (LMB)' ) cmds.text( l='(click here)' ) cmds.setParent( '..' ) frame2 = cmds.frameLayout( h=90, l='Copy of Original (LMB)' ) cmds.text( l='(click here)' ) cmds.setParent( '..' ) # Create a menu. # menu1 = cmds.popupMenu( parent=frame1, b=1, mm=True ) cmds.menuItem( rp='N', l='Up' ) cmds.menuItem( rp='S', l='Down' ) cmds.menuItem( rp='E', l='Right' ) cmds.menuItem( rp='W', l='Left' ) cmds.menuItem( label='Warm', sm=True ) cmds.menuItem( l='Red' ) cmds.menuItem( l='Orange' ) cmds.menuItem( l='Yellow' ) cmds.setParent( '..', m=True ) cmds.menuItem( label='Cold', sm=True ) cmds.menuItem( l='Green' ) cmds.menuItem( l='Blue' ) cmds.menuItem( l='Indigo' ) cmds.menuItem( l='Violet' ) cmds.setParent( '..', m=True ) cmds.setParent( '..', m=True ) # Save the menu to a file. # result = cmds.saveMenu(menu1, 'menu_example') # Use the file to rebuild another instance of the menu. # menu1 = cmds.popupMenu( parent=frame2, b=1, mm=True ) maya.mel.eval( 'source \"' + cmds.internalVar(userMarkingMenuDir=True) + 'menu_example.mel\"' ) # Finish up. print ("The menu was saved in [" + cmds.internalVar(userMarkingMenuDir=True) + result + "]\n" ) cmds.showWindow( win )