Accessing submenus / extension manager
-
I wrote a pair of ruby scripts that automatically rewrote the menu section of every script in the plugins folder (except for the utility scripts from SU) and then allowed users to organize their scripts into subfolders. It was temporarily available at http://www.smustard.com
One downfall was that double-clicking a file in the browser caused the scripts to not load. There might be a way around that now.
Another problem was that a few scripts couldn't be rewritten by the rewrite script because of strange formatting by the authors.
-
Hi Rick,
I think you're talking about the organizer.rb also Burkhard supported? I find it very useful. My idea was constistency in the Plugins menu of all users. That had to be done by hand, because @Last/Google does not provide a good Plugin mechanism. Also organizer.rb works with a categorization like my approach.
Maybe the Google guys are so nice adding a "Menu#submenus[]" or "Menu#parent" to the Menu class. That would simplify the problem. Than the only thing to manage would be to tetermine the categories and subcategories, the rest works automatically (with internationalization ). Do you know the person I have to contact for this request?
We would have some advantages of using a kind of my approach:
- consistency
- no dublicates in the menus
- Ruby programmers can write their code with own code style
- developing extensions gets more simple
- internationalization
- Ruby extensions build "the old way" also would work
- real Sketchup extensions, which you can switch on and off in the preferences
azuby
-
@Rick
you've found a solution running the script with SU6?
Btw. where on smustard is it? There is no organizer script with that name. -
Burkhard,
Yes, I fixed it last night and just sent it to you. There were a few reasons (like I mentioned above) that I took it off of Smustard, but am considering putting it back up.
-
RickW, please let us know here at the forum if / when you make the revised script available as well as where.
-
Juju,
Will do
-
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.
-
Yes Jim, I know that. If you go into the sources of the extensionmanager (mentioned in the first posting, first link - don't panic allthough it's a german website ), it is already done - a bit more complicated, because you have to remember the submenus for their parent menu, not all in the Menu object (you could have two "Preferences" menus coming from twot extensions). Thank you very much for verifying my problem.
azuby
-
Isn't this strange:
UI.menu().add_submenu '(none)' #<Sketchup;;Menu;0x1fba478> # => '(none)' in Plugins UI.menu("Plugouts").add_submenu 'Plugouts' #<Sketchup;;Menu;0xfbef4c0> # => 'Plugouts' in Plugins UI.menu("P").add_submenu 'P' #<Sketchup;;Menu;0xfba8c90> # => 'P' in Plugins UI.menu("p").add_submenu 'p' #<Sketchup;;Menu;0x102da520> # => 'p' in Plugins UI.menu("pong").add_submenu 'pong' #<Sketchup;;Menu;0x102abb70> # => 'pong' in Plugins UI.menu("Olugins").add_submenu 'Olugins' Exception `ArgumentError' at (eval);475 - Unknown menu olugins Exception `ArgumentError' at (eval);475 - (eval);475;in `menu'; Unknown menu olugins Error; #<ArgumentError; (eval);475;in `menu'; Unknown menu olugins> (eval);475 UI.menu("asdf").add_submenu 'asdf' Exception `ArgumentError' at (eval);475 - Unknown menu asdf Exception `ArgumentError' at (eval);475 - (eval);475;in `menu'; Unknown menu asdf Error; #<ArgumentError; (eval);475;in `menu'; Unknown menu asdf> (eval);475
azuby
-
("a".."z").each { |l| begin print "Trying #{l};" UI.menu(l).add_submenu('jim') puts "OK" rescue puts "Error on #{l}." end }
I don't like the "code" font, by the way; it's hard to read.
Advertisement