Notifications
Clear all

[Closed] Adding custom menu in main menubar

I want to create a menu in 3ds Max and add it to the main menu bar of 3ds Max using maxscript. How would I do this reading a xml file configured like this…

mymenu.xml

<MainMenu title="TEST">
    <Menu title="TEST_FRUIT">
        <Menu title="TEST_APPLE"></Menu>
        <Menu title="TEST_ORANGE"></Menu>
    </Menu>
    <Menu title="TEST_FOOD">
        <Menu title="TEST_SUISHI"></Menu>
        <Menu title="TEST_CHICKEN">
            <Menu title="TEST_CHICKEN_FAJITAS"></Menu>
            <Menu title="TEST_CHICKEN_TINGA"></Menu>
        </Menu>
    </Menu>
</MainMenu>

to create a menu that looks like this in 3ds max?

image

1 Reply
 MZ1
fn CreateMenu Name:"Name" Title:"Title" ParentMenu: =
(
	menuItem = menuMan.CreateMenu Name
	menuItem.setTitle Title
	subMenuItem = menuMan.createsubMenuItem Name menuItem
	if ParentMenu != undefined do ParentMenu.addItem subMenuItem -1
	menuItem
)

fn RecursiveAddMenu XmlNode ParentMenu =
(
	for i = 0 to XmlNode.ChildNodes.count - 1 do
	(
		childNode = XmlNode.ChildNodes.ItemOf i
		title = childNode.GetAttribute "title"
		Menu = CreateMenu Name:title Title:title ParentMenu:ParentMenu
		RecursiveAddMenu childNode Menu
	)
)	

xmlDoc = dotNetObject "System.Xml.XmlDocument"
xmlDoc.load @"C:\Users\New\Desktop\Temp\Menu.xml"
mainMenu = menuMan.getMainMenuBar()
RecursiveAddMenu xmlDoc mainMenu
menuMan.updateMenuBar()