[Closed] MenuMan sub menu menus
Hi
I have been wrapping my head around max`s menus with menuMan and think I just about get the basics but im having trouble adding menus that expand to other menus.
To see what i mean have a look at the modifiers menu in max`s main tool bar, every one has an arrow to expand into another menu.
Could someone show me how to do this pleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeease
thanks
I hope this works, i have just thrashed it out at home, its late now and havent tried it,
I shall update it with the actual code i have done at work tomorrow but it is definitely the gist of what i have written at work
in each script im creating a tag that im going to be using to separate the menuas out
ie modeling uvs materials etc…
something along the lines of
for each mcr
find tag
add to relevant sub menu
scriptsDir = getDir #scripts
mcrScripts = getFiles (scriptsDir + "\\Startup\\*.mcr")
for f in mcrScripts do
(
fileIn f
)
mainMenuBar = menuMan.getMainMenuBar()
toolsMenu = menuMan.createMenu "ToolsMenu"
local toolsMenu
for i = 1 to mcrScripts.count do
(
macroName = getMacroName mcrScripts[i]--returns a string
item = menuMan.createActionItem macroName "Tools"
toolsMenu.addItem item -1
toolsMenuItem = menuMan.createSubMenuItem "Test Menu" toolsMenu
)
mainMenuBarItems = mainMenuBar.numItems() -1--zero based
mainMenuBar.addItem toolsMenu mainMenuBarItems
menuMan.updateMenuBar()
Updated so it might actually work (without sub menus)
now i see that you’ve tried do it at least
here is a sample how to do it… try to understand how it works yourself.
(
menu = menuMan.createMenu "Custom Tools"
sub = menuMan.createMenu "Apply Modifier"
a = menuMan.createActionItem "Bend" "Modifiers"
sub.addItem a -1
b = menuMan.createActionItem "Taper" "Modifiers"
sub.addItem b -1
item = menuMan.createSubMenuItem "Apply Modifier" sub
menu.addItem item -1
mitem = menuMan.createSubMenuItem "Custom Tools" menu
index = mainMenuBar.numItems() -- add before last (usualy it's "Help")
mainMenuBar.addItem mitem index
menuMan.updateMenuBar()
)
cheers denis
my code (at work at least) does work and it only supposed to create a single long list of all the scripts in our startup folder,which it does
thanks for the example code works like a charm
I should have figured that out, might have been staring at it too long
cheers
fn createCatagorizedMenu =
(
lMenu = menuMan.findMenu "Tools"
if lMenu != undefined do
(
menuMan.unRegisterMenu lMenu
menuMan.updateMenuBar()
lMenu = menuMan.findMenu "Tools" -- need to check it again after destroying the menu
)
if lMenu == undefined do
(
toolTypes = #()
mcrMacros = getFiles (scriptsDir + "\\Startup\\*.mcr")
for i = 1 to mcrMacros.count do
(
toolType = getToolType mcrMacros[i]
appendIfUnique toolTypes toolType
)
mainMenuBar = menuMan.getMainMenuBar()--main toolbar
ToolsMenu = menuMan.createMenu "Tools" -- create menu object
for type in toolTypes do
(
subMenu = menuMan.createMenu type
for i = 1 to mcrMacros.count do
(
toolType = getToolType mcrMacros[i]--returns a custom tag
if toolType == type do
(
scriptName = getMacroScriptName mcrMacros[i]--returns the macroscript name
item = menuMan.createActionItem scriptName "Tools"
subMenu.addItem item -1
)
)
subItem = menuMan.createSubMenuItem type subMenu
ToolsMenu.addItem subItem -1
)
index = mainMenuBar.numItems()
ToolsItem = menuMan.createSubMenuItem "Tools" ToolsMenu
mainMenuBar.addItem ToolsItem index
menuMan.updateMenuBar()
)
)
thanks denis
i can’t test it without getToolType and getMacroScriptName functions but everything looks right…
except… it works for situation ‘one-file – one-macro’ which is not always true.
the right way is to use macros.list. it’s undocumented but you can redirect list output to any stream. after that just parse the data, find your macros by file, category, whatever… and make menus:
ss = stringstream ""
macros.list to:ss
ss as array
yeah sorry cant really post the entire file but it does work as do the other functions
as for macros.list(), i didnt know about that functionality, just recently returned to Mxs, been doing it 4 days now after pymel for a few years
getMacroScriptName() goes through the mcr file string stream and finds the macrosript sting, then the name is the next value and I know the category already. Its a a fairly heavy function for just that info so maybe macros.list() will be better, i shall investigate more tomorrow.
getToolType() does a similar thing but searches for a string that will be the categories my studio wants to use and returns that string to populate the menus with
As for ‘one-file – one-macro’ thats the way im intending to do the mcr`s, i have a few ms scripts at the moment and im wrapping them in a simple macrosript with a fileIn of the ms to have the ability to run it from code and via the UI, BUT im not saying it wont change in the future
From what i have learnt in the menuMan :-
any menuObject can have action items
that menu can be “converted” into a sub menu item (createSubMenuItem)
that sub menu item can then be added to a parent menu object
rinse and repeat for however deep a menus you want
this conversion is what seemed odd to me with the MenuObeject and the Item being so similar in the docs, the subject is quite simple really but the documentation/naming could be vastly improved imho
anywho thanks for the help