You can work with 3ds Max menus using these interfaces:
menuMan
menuItem
quadMenu
Be very careful when using or testing the menuMan
API. It makes permanent changes to the menu database, and it is very easy to corrupt the menus. For example, if you "unRegister" the main menu bar, 3ds Max won't start. Before using this API, make a copy of the "..\UI\MaxStartUI.mnu" file so you can easily restore it if any problems arise.
A menu item is typically associated with a MacroScript, which is executed when that menu item is pressed. In the following example we create a Python function, connect it to a pymxs runtime global variable, and then define a macroscript using macros.new()
. In this case, we simply invoke our Python function.
Next, we find the Help menu using menuMan.find(), create a new menuitem that invokes our macroscript, and add it to the Help menu.
from pymxs import runtime as rt
# Our Py function:
def myfunc():
print('hello world')
# Connect to a gobal in the runtime:
rt.mxs_hello = myfunc
macroscript_name = 'My_Macroscript'
macroscript_category = 'Test'
macroscript_tooltip = 'This is a tooltip'
# this sets the text used for any menus or ui controls
# associated with this macroscript
macroscript_text = 'My Macroscript'
# this is a MAXSCript:
macroscript_content = 'mxs_hello()'
macro_id = rt.macros.new(macroscript_category, macroscript_name, macroscript_tooltip, macroscript_button, macroscript_content)
# Now we can create a menu item for this script
help_menu = rt.menuMan.findMenu('&Help')
menu_item = rt.menuMan.createActionItem(macroscript_name, macroscript_category)
help_menu.addItem(menu_item, -1)
rt.menuMan.updateMenuBar()
# this can be removed by:
# help_menu.removeItem(menu_item)
For more information, see the following topics in the MAXScript Help: