Notifications
Clear all
[Closed] Create a submenu in a submenu
Nov 09, 2017 3:33 am
Hi all
Been reading the docs and forums wrapping my head around menu and item creation.
Bobo posted this a while back:
macroScript PutMeOnAMenu category:"Forum Help" --some macro script
(
print "I do nothing, but I am on a Menu!"
)
theMainMenu = menuMan.getMainMenuBar() --get the main menu bar
theMenu = menuMan.createMenu "Forum Help" --create a menu called Forum Help
theSubMenu = menuMan.createSubMenuItem "Forum Help" theMenu --create a SubMenuItem
theMainMenu.addItem theSubMenu (theMainMenu.numItems()+1) --add the SubMenu to the Main Menu
theAction = menuMan.createActionItem "PutMeOnAMenu" "Forum Help" --create an ActionItem from the MacroScript
theMenu.addItem theAction (theMenu.numItems()+1) --add the ActionItem to the menu
menuMan.updateMenuBar() --update the menu bar
What If I wanted a submenu in a submenu, how could I modify the code for that? Tried a bunch of things, but nothing seem to work.
The code above results in:
Forum Help > PutMeOnAMenu
I want to change the code above to result in:
Forum Help > Stuff from Bobo > PutMeOnAMenu
2 Replies
Nov 09, 2017 3:33 am
Is this what you want below?
macroScript PutMeOnAMenu category:"Stuff from Bobo" --some macro script
(
print "I do nothing, but I am on a Menu!"
)
theMainMenu = menuMan.getMainMenuBar() --get the main menu bar
theMenu = menuMan.createMenu "Forum Help" --create a menu called Forum Help
theSubMenu = menuMan.createSubMenuItem "Forum Help" theMenu --create a SubMenuItem
theMainMenu.addItem theSubMenu (theMainMenu.numItems()+1) --add the SubMenu to the Main Menu
theMenu2 = menuMan.createMenu "Stuff from Bobo"
theSubMenu2 = menuMan.createSubMenuItem "Stuff from Bobo" theMenu2
theMenu.addItem theSubMenu2 (theMenu.numItems()+1)
theAction = menuMan.createActionItem "PutMeOnAMenu" "Stuff from Bobo" --create an ActionItem from the MacroScript
theMenu2.addItem theAction (theMenu2.numItems()+1) --add the ActionItem to the menu
menuMan.updateMenuBar() --update the menu bar
Nov 09, 2017 3:33 am
It’s clear that Menu items are not clear!
That’s how I do it. Hope it helps.
-- Creation of a Main Menu Item
-- Creates a main item with NON Executable subItems that may have several Executables subItems
(
function createNewMainMenuBarItem mainMenuName subMenusData =
(
-- kills a menu by name
-- Note: A menu may exist even if it does not appear in the MainMenu bar
mapped function killMenu menuName =
(
menu = menuMan.findMenu menuName
if menu != undefined do menuMan.unRegisterMenu menu
)
-- appends an executable macro item to a menu
-- default position is last position (-1)
function appendItem menu macroScriptName macroScriptCategory:"Proin3D" position:-1 =
(
item = menuMan.createActionItem macroScriptName macroScriptCategory
if item != undefined then menu.addItem item position else print ("ERROR: Macro missing " + macroScriptName )
)
-- appends a separator item to a menu (by defualt in last position)
function appendSep menu position:-1 =
(
separator = menuMan.createSeparatorItem()
menu.addItem separator position
)
-- appends a new non executable subMenu item (containing executable items) to a parentMenu
-- the names displayed are those of the executable items. The internalName is not displayed
-- By default, added to the last position
function appendSubMenu parentMenu subMenuInternalName subMenu position:-1 =
(
menu = menuMan.createSubMenuItem subMenuInternalName subMenu
if menu != undefined then parentMenu.addItem menu position else print "ERROR: Unable to create sub-menu"
)
-- delete any already existing custom menu with the given names
killMenu mainMenuName
for menu in subMenusData do killMenu menu.publicName
-- create Main Menu
local mainMenu = menuMan.createMenu mainMenuName
-- create SubMenus and Add them to MainMenu
local subMenus = for menu in subMenusData collect
(
subMenu = menuMan.createMenu menu.publicName
appendSubMenu mainMenu menu.internalName subMenu
if menu.separator do appendSep mainMenu
subMenu
)
-- Add MacroScripts to SubMenus
for k = 1 to subMenusData.count do
(
for theMacro in subMenusData[k].asociatedMacros do
(
appendItem subMenus[k] theMacro.macroName
if theMacro.separator do appendSep subMenus[k]
)
)
-- Create the Menu in the Main Menu Bar (in last position before the Help)
mainMenuBar = menuMan.getMainMenuBar()
index = mainMenuBar.numItems() -- add before last (usualy it's "Help")
theNewMenu = menuMan.createSubMenuItem mainMenuName mainMenu
mainMenuBar.addItem theNewMenu index
menuMan.updateMenuBar()
--------------------------------------------------------------------------------------
-- To append a sub-subMenu to a subMenu:
-- appendSep subMenu
-- subSubMenu = menuMan.createMenu subSubMenuName
-- appendSubMenu subMenu subSubMenuInternalName subSubMenu
-- appendItem subSubMenu theMacroScriptName
--------------------------------------------------------------------------------------
)
fn deleteCreatedMenus mainMenuName subMenuNamesList =
(
mapped function killMenu menuName =
(
menu = menuMan.findMenu menuName
if menu != undefined do menuMan.unRegisterMenu menu
)
killMenu mainMenuName
killMenu subMenuNamesList
)
-----------------------
-- The DATA
-----------------------
-- Main Menu Item Name (Public and Internal name)
mainMenuName = "Proin 3D"
-- SubMenus List (public names, internal names and asociated macroscript names for each submenu) (Public and internal names may be the same)
subMenuNamesList = #("Proin 3D - CargaEscamas", "Proin 3D - PonCoche", "Proin 3D - PutCar", "Proin 3D - Catenaria", "Proin 3D - Utilidades", "Proin 3D - PlacePeople")
subMenuInternalNamesList = #("CargaEscamas", "PonCoche", "PutCar", "Catenaria", "Utilidades", "PlacePeople")
subMenuSeparators = #(true, false, true, true, true, false)
subMenuAsociatedMacros = #( #("MacroCargaEscamas") \
,#("MacroPonCoche") \
,#("MacroPutCarManager", "MacroPutCarAssign", "MacroConvertPoncoche", "MacroPutFreeCamAssign") \
,#("MacroCatenaria") \
,#("MacroAplastaMesh", "MacroDepuraLinea", "MacroParalela", "MacroExtruir2015", "MacroCreateMainPK") \
,#("MacroPlacePeople") \
)
subMenuAsociatedMacrosSeparators = #(#(false) \
,#(false) \
,#(false, false, true, false) \
,#(false) \
,#(true, false, false, true, false) \
,#(false) \
)
------------ END OF DATA
-- Initialize subMenus data
struct subMenuStruct (publicName, internalName, separator, asociatedMacros)
struct asocMacroStruct (macroName, separator)
subMenusData = for k = 1 to subMenuNamesList.count collect
(
subMenu = subMenuStruct publicName:subMenuNamesList[k] internalName:subMenuInternalNamesList[k] separator:subMenuSeparators[k]
subMenu.asociatedMacros = for kk = 1 to subMenuAsociatedMacros[k].count collect
(
theMacro = asocMacroStruct macroName:subMenuAsociatedMacros[k][kk] separator:subMenuAsociatedMacrosSeparators[k][kk]
)
subMenu
)
-- CALL the creation Menu Function
createNewMainMenuBarItem mainMenuName subMenusData
-- DELETE created Menus
-- deleteCreatedMenus mainMenuName subMenuNamesList
)
Have a happy Christmas holidays and a good year 2018!