[Closed] Creating a submenu in 3dsmax's File menu
Hi,
I coded a customized mesh exporter using MaxScript and I would like to add it to 3dsmax’s File menu. Please, is there an way to do this with MaxScript? I would like to add it below the “Export Selected…” description.
Thanks in advance
yes there is
First, you’ll have to create a macroscript for your exporter. Your export function should then be in the macro’s “on execute do” event, just as it would be if you placed it in a button on a toolbar.
Next, you use menuMan (see Help file) to create a menu item that refers to that macroscript, find the “Export Selected…”* menu item, add your own new item just below it, and finally update the menu.
-
Note that on German, French, Japanese, etc. versions of 3ds Max, that won’t be “Export Selected…”. Unfortunately you can’t get at any ‘internal’ type name for these commands, so you’ll have to find people with those versions and get them to give you the correct string. The below code has an “else if” specifically for these localized versions already in place for that reason.
Edit – happen to have menu string dumps for German and French versions, so…:
For German, the string is: “Auswahl exportieren…”
For French, the string is: “Exporter sélection…”Because you might want to have a different label in the menu than you do on toolbar buttons (toolbar buttons being rather narrow, whereas the menu permits you longer labels), you can use ‘.setTitle’ and ‘.setUseCustomTitle true’ to make that happen; otherwise the Menu entry will just use the button text.
Finally, because you probably only want your item to appear once, you should scan the menu to make sure your item isn’t already in there. Unfortunately you’re a bit limited in MaxScript in determining that; the easiest way is to simply check if the menu item is using the label/title you gave it – making sure to use the text used in ‘.setTitle’ to identify it.
macroscript fileMenuTest buttontext:"file menu test" category:"test" ( )
(
local myItem = menuMan.createActionItem "fileMenuTest" "test"
myItem.setTitle "File Menu test (alternative)"
myItem.setUseCustomTitle true
local mainMenu = menuMan.getMainMenuBar()
local fileMenu = (mainMenu.getItem 1).getSubMenu()
local exportSelectedIndex
local addItem = true
for i = 1 to (fileMenu.numItems()) do (
local item = fileMenu.getItem i
local itemTitle = item.getTitle()
if (itemTitle == "File Menu test (alternative)") then ( addItem = false; exit )
else if (itemTitle == "Export Selected...") then ( exportSelectedIndex = i )
-- else if (itemTitle == "<localized versions for DE, FR, JP, etc.>") then ...
)
if (addItem AND (exportSelectedIndex != undefined)) then (
fileMenu.addItem myItem (exportSelectedIndex+1)
)
menuMan.updateMenuBar()
)
Please note that messing with max’s UI can be dangerous – as pointed out by the help file. The above code is pretty benign, and you can remove the menu item through the Customize > Customize User Interface… options.