Notifications
Clear all
[Closed] Adding Menu
Dec 05, 2017 5:38 pm
I’m simply trying to add a separator and action to a menu in 3ds Max using python. However the FindMenu method returns a pointer to the menu but doesn’t not give me the ability to add anything to that menu? Can someone help me figure out what I’m doing wrong here?
import os
import sys
import MaxPlus
MaxPlus.Core.EvalMAXScript('ClearListener()')
def remove_menu_by_name(name):
while True:
menu = MaxPlus.MenuManager.FindMenu(name)
if not menu:
break
numMenuItems = menu.GetNumItems()
if numMenuItems:
for i in range(numMenuItems): #(numMenuItems-1, -1, -1)
item = menu.GetItem(i).GetSubMenu()
if item:
remove_existing_menu(item.GetTitle())
MaxPlus.MenuManager.UnregisterMenu(menu)
def create_menu(name):
menu = MaxPlus.MenuManager.FindMenu(name)
if not MaxPlus.MenuManager.MenuExists(name):
mb = MaxPlus.MenuBuilder(name)
menu = mb.Create(MaxPlus.MenuManager.GetMainMenu())
return menu
def doSomething():
print 'Something happened'
# Create Menu
remove_menu_by_name('Artists Tools')
menu = create_menu('Artists Tools')
menu.AddSeparator()
action = MaxPlus.ActionFactory.Create('Do something', 'Python demos', doSomething)
menu.AddItem(action)
menu.AddSeparator()