azuby,
I came up with this code. It stores the menu object in a Hash on creation. But it doesn't work for the reasons you stated.
class Sketchup;;Menu
@@submenus = {}
alias ;old_add_submenu ;add_submenu
def add_submenu(name)
@@submenus[name] = old_add_submenu(name)
end
def self.submenus
@@submenus
end
end
Well, it builds the hash correctly, and you can access the sub menus by name:
Sketchup;;Menu.submenus["SomeName"].add_item("Say Hi") { UI.messagebox("Hi!") }
The above example does not work. It give no error, but it doesn't add the menu item either. Too bad as it would then be dead simple to hijack the add_submenu and add_item methods to create the menu tree, and no script would need changed to fit into a certain category.