sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Question about menu.add_item

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 4 Posters 778 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.
    • W Offline
      wikii
      last edited by

      amenu=UI.menu("Plugins").add_submenu("Test")
      amenu.add_item("print 1"){print 1}

      I Run each line of the codes in Ruby Console , Only a submenu "Test" has been added in plugins menu."Print 1" does not show in the submenu "Test".

      If I save the codes in a rb file and load it in Ruby Console,submenu "Test" and "Print 1" will be shown correctly.

      why?

      1 Reply Last reply Reply Quote 0
      • S Offline
        sahi
        last edited by

        amenu=Ui.menu("Plugins").add_submenu("Test") - the script execute the command executed and the variable "amenu" - forgotten
        amenu=false

        We can do this

        amenu=Ui.menu("Plugins").add_submenu("Test")**;**amenu.add_item("print 1"){print 1}

        or so

        Ui.menu("Plugins").add_submenu("Test").add_item("print 1"){print 1}

        1 Reply Last reply Reply Quote 0
        • W Offline
          wikii
          last edited by

          I just want to add all my plugins to one submenu.
          I use a global variable to store the submenu.but it does not work.

          Is there a way to add defferent plugins to one submenu?

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            @wikii said:

            amenu=UI.menu("Plugins").add_submenu("Test")
            amenu.add_item("print 1"){print 1}

            I Run each line of the codes in Ruby Console , Only a submenu "Test" has been added in plugins menu."Print 1" does not show in the submenu "Test".

            If I save the codes in a rb file and load it in Ruby Console,submenu "Test" and "Print 1" will be shown correctly.

            why?

            I've noticed this before as well. Dunno why. Some kind of bug.

            Thomas Thomassen β€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • TIGT Online
              TIG Moderator
              last edited by

              Use
              $wikii_submenu=UI.menu("Plugins").add_submenu("Wikii")
              then later
              $wikii_submenu.add_item("Print 1"){print 1} $wikii_submenu.add_item("Print 2"){print 2}
              etc, should work...

              It works in the console because the $global is remembered.

              Also setting a global reference [$] for your actual tool means that as long as the .rb file making the submenu loads first [start its file name with a ! or ###], then other scripts can access the submenu and add items to it too - that's how I manage many of my main Plugins, using submenus 0 to 9 logically named and ordered to contain similar types of tools... Other stuff lives 'loose' in Plugins menu or wherever...
              Remember to use a $ name that's unlikely to be reused by some one else - e.g. $menu = bad idea as it could easily used by someone else, but $wikii_submenu likely to be 'uncommon'...

              TIG

              1 Reply Last reply Reply Quote 0
              • W Offline
                wikii
                last edited by

                @tig said:

                Use
                $wikii_submenu=UI.menu("Plugins").add_submenu("Wikii")
                then later
                $wikii_submenu.add_item("Print 1"){print 1} $wikii_submenu.add_item("Print 2"){print 2}

                Thank you,TIG!

                But,it does not work when I copy it to Ruby Console line by line.
                Only "Wikii" has been added to plugins menu.
                "print 1" and "print 2" do not show.

                1 Reply Last reply Reply Quote 0
                • TIGT Online
                  TIG Moderator
                  last edited by

                  WikiiI see what you me - buggy...
                  However it WILL work when scripted...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • W Offline
                    wikii
                    last edited by

                    @tig said:

                    WikiiI see what you me - buggy...
                    However it WILL work when scripted...

                    I hope it works in different scritps,means that two scripts can add items to a same submenu.

                    1 Reply Last reply Reply Quote 0
                    • TIGT Online
                      TIG Moderator
                      last edited by

                      @wikii said:

                      @tig said:

                      WikiiI see what you me - buggy...
                      However it WILL work when scripted...

                      I hope it works in different scripts, means that two scripts can add items to a same submenu.

                      It does work in different scripts, if you use a $ variable - I already use it like that...

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • W Offline
                        wikii
                        last edited by

                        @tig said:

                        @wikii said:

                        @tig said:

                        WikiiI see what you me - buggy...
                        However it WILL work when scripted...

                        I hope it works in different scripts, means that two scripts can add items to a same submenu.

                        It does work in different scripts, if you use a $ variable - I already use it like that...

                        I test these two file.
                        Only 1.rb work well,2.rb can't add item into the submenu.


                        load the first


                        then this one

                        1 Reply Last reply Reply Quote 0
                        • TIGT Online
                          TIG Moderator
                          last edited by

                          They DO work....
                          BUT you have to let Sketchup auto-load them as it starts.

                          You can't push a new item into a submenu by manually loading script files later on, or typing the commands into the console.
                          If I put both of your .rb files into my Plugins folder and restart Sketchup then I get the ../Plugins/Wikii/ submenu with the two specified items added - each one created by their separate script using the $ global ref...

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • W Offline
                            wikii
                            last edited by

                            I see.

                            Thank you,Tig!

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

                            Advertisement