Hello,
I have two C++ plugins which register lots of menu entries. These are not generated under the usual "Extensions" / custom plugin menu, but in an own top level menu and its submenus. That works and look like that:
MyMenu
MySubmenu1
MyMenuItem1
MySubmenu2
MyMenuItem2
Now I want to register a Python
script to add a menu item after MyMenuItem2, but it appears after MyMenuItem1.
MyMenu
MySubmenu1
MyMenuItem1
MyMenuItem3 // here it appears, created from Python
MySubmenu2
MyMenuItem2a
MyMenuItem2b
MyMenuItem2c
*MyMenuItem3* // here it should appear
I used the official example for building menus and an older forum post How to add a plugin to a toolbar menu?
My code is
def EnhanceMenu():
# getting the main menu resource container
menu = c4d.gui.GetMenuResource("M_EDITOR")
# find our menu
customMenu = None
for bcMenuId, bcMenu in menu:
#print(" " + str(bcMenuId) + " " + str(bcMenu))
if bcMenu != 1: #?
#print(bcMenu[c4d.MENURESOURCE_SUBTITLE])
if bcMenu[c4d.MENURESOURCE_SUBTITLE] == "MyMenu":
customMenu = bcMenu
#customMenu = menu.GetContainerInstance(bcMenuId)
break
print(customMenu)
# find our submenu
customMenu = None
menu = customMenu
for bcMenuId, bcMenu in menu:
if bcMenu != 1: #?
#print(" " + str(bcMenuId) + " " + str(bcMenu))
#print(bcMenu[c4d.MENURESOURCE_SUBTITLE])
if bcMenu[c4d.MENURESOURCE_SUBTITLE] == "MySubMenu2":
customMenu = bcMenu
break
print(customMenu)
# test debug output submenu content
menu = customMenu
for bcMenuId, bcMenu in menu:
if bcMenu != 1: #?
print(" " + str(bcMenuId) + " " + str(bcMenu))
print(bcMenu[c4d.MENURESOURCE_SUBTITLE])
print(bcMenu[c4d.MENURESOURCE_STRING])
# create new menu item
customMenu.InsData(c4d.MENURESOURCE_COMMAND, "PLUGIN_CMD_" + str(MY_COMMAND_ID))
c4d.gui.UpdateMenus()
def PluginMessage(id, data):
if id == c4d.C4DPL_BUILDMENU:
EnhanceMenu()
I know the code is a bit redundant and I compare the menu text instead of the id, but there was not id set in C++. Worth to mention is that the test debug out submenu content prints
4 MySubMenu2
i
t
3 PLUGIN_CMD_1000001
I
N
3 PLUGIN_CMD_1000002
I
N
3 PLUGIN_CMD_1000003
I
N
The expected strings should be MyMenuItem2a, MyMenuItem2b and MenuItem2c instead of single letters. The commands are correct. And why is MyMenuItem3 within MySubmenu1?
Has someone any idea?
Chris