sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Update | Sketchucation Tools 5.0.8 released with licensing improvements and bugfixes Download

    [API] Menu.add_item( caption, index )

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 3 Posters 742 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.
    • thomthomT
      thomthom
      last edited by

      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
      • thomthomT
        thomthom
        last edited by

        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
          Jim
          last edited by

          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
          • thomthomT
            thomthom
            last edited by

            @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
            • Dan RathbunD
              Dan Rathbun
              last edited by

              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
                Jim
                last edited by

                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
                • thomthomT
                  thomthom
                  last edited by

                  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
                    Jim
                    last edited by

                    Just confirmed it does work in sub-menus.

                    2012-11-04_134125.jpg

                    Hi

                    1 Reply Last reply
                    Reply Quote 0

                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                    With your input, this post could be even better 💗

                    Register Login
                    • 1 / 1
                    • First post
                      Last post
                    Buy SketchPlus
                    Buy SUbD
                    Buy WrapR
                    Buy eBook
                    Buy Modelur
                    Buy Vertex Tools
                    Buy SketchCuisine
                    Buy FormFonts

                    Advertisement