• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

[API] Menu.add_item( caption, index )

Scheduled Pinned Locked Moved Developers' Forum
8 Posts 3 Posters 426 Views 3 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.
  • T Offline
    thomthom
    last edited by 30 Oct 2012, 15:16

    Looking at the exporter for the STL project and I noticed an argument I wasn't aware was possible on #add_item.

    <span class="syntaxdefault">UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'Plugins'</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'First Post!'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> puts </span><span class="syntaxstring">'w00t!'</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">}</span><span class="syntaxdefault"></span>
    

    😲

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

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 30 Oct 2012, 15:54

      Apparently added very recently. Use feature guard before using:

      <span class="syntaxdefault"><br /></span><span class="syntaxkeyword">if&nbsp;</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Menu</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">instance_method</span><span class="syntaxkeyword">(;</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">arity&nbsp;</span><span class="syntaxkeyword">==&nbsp;</span><span class="syntaxdefault">1<br />&nbsp;&nbsp;UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'Plugins'</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'Last&nbsp;Post...'</span><span class="syntaxkeyword">)&nbsp;{&nbsp;</span><span class="syntaxdefault">puts&nbsp;</span><span class="syntaxstring">';('&nbsp;</span><span class="syntaxkeyword">}<br />else<br />&nbsp;&nbsp;</span><span class="syntaxdefault">UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'Plugins'</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'First&nbsp;Post!'</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">)&nbsp;{&nbsp;</span><span class="syntaxdefault">puts&nbsp;</span><span class="syntaxstring">'w00t!'&nbsp;</span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault">end<br /></span>
      

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

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by 30 Oct 2012, 20:06

        What happens when everyone wants to be first? I guess that would make the Plugins menu be in reverse load order.

        Hi

        1 Reply Last reply Reply Quote 0
        • T Offline
          thomthom
          last edited by 30 Oct 2012, 20:43

          @jim said:

          What happens when everyone wants to be first? I guess that would make the Plugins menu be in reverse load order.

          Yup! There is no way that argument will be of any assurance to where the menu appears. But as in the case of the STL exporter, you can at least place it nearer where you want it.

          I don't see myself using it too much though. The exporter is one of them use cases for it until they implement an Exporter class.

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

          1 Reply Last reply Reply Quote 0
          • D Offline
            Dan Rathbun
            last edited by 30 Oct 2012, 22:09

            No doubt an interesting find.

            However I would prefer a fully documented API dictionary rather than hidden easter eggs. (I think the easter egg scenario has gone out of style in favor of "truth in software" or whatever it is called.)

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jim
              last edited by 3 Nov 2012, 16:16

              This might be useful in a sub-menu. Does anyone know if it works in a sub-menu as well as top-level menus?

              Hi

              1 Reply Last reply Reply Quote 0
              • T Offline
                thomthom
                last edited by 3 Nov 2012, 16:35

                Haven't tried. (I just assumed.)

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

                1 Reply Last reply Reply Quote 0
                • J Offline
                  Jim
                  last edited by 4 Nov 2012, 18:37

                  Just confirmed it does work in sub-menus.

                  2012-11-04_134125.jpg

                  Hi

                  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