Adding more plugins to submenu?
-
I've developed a Plugin (PluginA) which creates a submenu called "Create..." under the main menu "Plugins"
plugins_menu = UI.menu("PlugIns")
create_submenu = plugins_menu.add_submenu("Create...")
create_submenu.add_item("PluginA")Then I created a second separate plugin (PluginB) that I also want to place in the "Create..." submenu. I can't figure out how to place the second plugin (PluginB) in the submenu "Create...".
Anyone have any ideas?
Thanks
Derek -
create_submenu.add_item("PluginB")
That should do it!
-
You can create the plugins within the same 'module': then use the same '@' reference to the submenu
@submenu=UI.menu.add_submenu('xxx') if not @submenu @submenu.add_item('yyy'){...}
[OR you can use a 'module' 'CONSTANT' like SUBMENU=UI.menu.add_submenu('xxx') if not SUBMENU]
this will work for any new methods defined that are related to that 'module'...
OR you can use a global reference '$' [somewhat dangerous] in every script [use an unlikely name so clashes with others are minimized!]
Then in every 'linked' script use
@sscribble_submenu=UI.menu.add_submenu('xxx')if not @sscribble_submenu @sscribble_submenu.add_item('yyy'){...}
OR you can use a class variable '@@' that relates to a give 'class' - that might have several 'versions'.
` @@sscribble_submenu=UI.menu.add_submenu('xxx')if not @@sscribble_submenuthen later
@@sscribble_submenu.add_item('yyy'){...}`
-
@chris fullmer said:
create_submenu.add_item("PluginB")
That should do it!
The plugins are two separate ruby files plugina.rb & pluginb.rb. They load independently.
plugina.rb will load first and create the "Create..." submenu under "Plugins".
I'm just not sure how to code pluginb.rb to use the same submenu created in plugina.rb
-
@scetchnscribble said:
@chris fullmer said:
create_submenu.add_item("PluginB")
That should do it!
The plugins are two separate ruby files plugina.rb & pluginb.rb. They load independently.
plugina.rb will load first and create the "Create..." submenu under "Plugins".
I'm just not sure how to code pluginb.rb to use the same submenu created in plugina.rb
Have you not read my step by step guide
-
TIG, what do you mean by "create them in the same module"?
-
@Derek: All of your plugin scripts should run within your personal toplevel namespace (module.) Your various plugin scripts can run within their own submodule of your "Author" module.
The outer module can hold a reference, which can be a constant (since it will not change during the session.) Constants are all uppercase.
file: "derek/derek_mod.rb"
module Derek MENU_PLUGINS = UI.menu("Plugins") unless defined?(MENU_PLUGINS) SUBMENU_CREATE = MENU_PLUGINS.add_submenu("Create...") unless defined?(SUBMENU_CREATE) end # module Derek
file: "derek/plugin_A.rb"
require("derek/derek_mod.rb") require("sketchup.rb") module Derek;;PluginA # module methods, module vars, etc. unless file_loaded?(File.basename(__FILE__)) Derek;;SUBMENU_CREATE.add_item('yyy'){ # code block... } file_loaded(File.basename(__FILE__)) end end # module Derek;;PluginA
file: "derek/plugin_B.rb"
require("derek/derek_mod.rb") require("sketchup.rb") module Derek;;PluginB # module methods, module vars, etc. unless file_loaded?(File.basename(__FILE__)) Derek;;SUBMENU_CREATE.add_item('yyy'){ # code block... } file_loaded(File.basename(__FILE__)) end end # module Derek;;PluginB
-
Dan,
Thanks I finally got it to work using the code you provided.
Derek
Advertisement