• Login
sketchucation logo sketchucation
  • Login
ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

Adding more plugins to submenu?

Scheduled Pinned Locked Moved Developers' Forum
8 Posts 4 Posters 317 Views 4 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    scetchnscribble
    last edited by 26 Oct 2011, 19:32

    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

    1 Reply Last reply Reply Quote 0
    • C Offline
      Chris Fullmer
      last edited by 26 Oct 2011, 19:42

      create_submenu.add_item("PluginB")

      That should do it!

      Lately you've been tan, suspicious for the winter.
      All my Plugins I've written

      1 Reply Last reply Reply Quote 0
      • T Offline
        TIG Moderator
        last edited by 26 Oct 2011, 19:49

        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_submenu

        then later

        @@sscribble_submenu.add_item('yyy'){...}`
        😕

        TIG

        1 Reply Last reply Reply Quote 0
        • S Offline
          scetchnscribble
          last edited by 26 Oct 2011, 20:14

          @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

          1 Reply Last reply Reply Quote 0
          • T Offline
            TIG Moderator
            last edited by 26 Oct 2011, 20:18

            @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

            1 Reply Last reply Reply Quote 0
            • S Offline
              scetchnscribble
              last edited by 26 Oct 2011, 20:22

              TIG, what do you mean by "create them in the same module"?

              1 Reply Last reply Reply Quote 0
              • D Offline
                Dan Rathbun
                last edited by 26 Oct 2011, 20:27

                @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
                

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • S Offline
                  scetchnscribble
                  last edited by 26 Oct 2011, 21:16

                  Dan,

                  Thanks I finally got it to work using the code you provided.

                  Derek

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  1 / 1
                  • First post
                    1/8
                    Last post
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement