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!
    🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Tool.onCancel - Reselect tool?

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 5 Posters 1.2k Views 5 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 Offline
      thomthom
      last edited by

      https://developers.google.com/sketchup/docs/ourdoc/tool#onCancel

      @unknownuser said:

      1: the user re-selected the same tool from the toolbar or menu.

      I can't seem to get reason code 1 to trigger. Only 0 and 2.
      I thought I'd used it before - but I'm unsure. 😕

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

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

        Test snippet:

        <span class="syntaxdefault"><br />class MyTool<br /><br />  def activate<br />    puts </span><span class="syntaxstring">"activate; #{self}"<br /></span><span class="syntaxdefault">  end<br /><br />  def deactivate</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> view </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    puts </span><span class="syntaxstring">"deactivate; #{self}"<br /></span><span class="syntaxdefault">  end<br /><br />  def onCancel</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">reason</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> view</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    puts </span><span class="syntaxstring">"MyTool was cancelled for reason #{reason}"<br /></span><span class="syntaxdefault">  end<br /><br />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
        • fredo6F Offline
          fredo6
          last edited by

          @thomthom said:

          https://developers.google.com/sketchup/docs/ourdoc/tool#onCancel

          @unknownuser said:

          1: the user re-selected the same tool from the toolbar or menu.

          I can't seem to get reason code 1 to trigger. Only 0 and 2.
          I thought I'd used it before - but I'm unsure. 😕

          Never got code 1 either. So I usually only test 0 or not 0

          Fred

          1 Reply Last reply Reply Quote 0
          • A Offline
            Aerilius
            last edited by

            Is 1 (technically) possible?
            Do "radio" toolbar buttons trigger an action if the current state is not changed?
            Do toolbar buttons in the OS X version behave the same way?

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

              You can click a menu or toolbar button that activates a tool. It does triggesr the action and activates the tool again, but it deactivates the tool instead of calling this event.

              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 Offline
                Dan Rathbun
                last edited by

                👿 (Devil's Advocate)

                Are you dealing with a single re-usable Tool instance ?

                Or does the command create a new Tool instance each time the menu item is chosen ?

                I'm not here much anymore.

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

                  @dan rathbun said:

                  Are you dealing with a single re-usable Tool instance ?

                  Or does the command create a new Tool instance each time the menu item is chosen ?

                  Either way - I'm unable to trigger that event.

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

                  1 Reply Last reply Reply Quote 0
                  • eneroth3E Offline
                    eneroth3
                    last edited by

                    This seems like a documentation error. However when re-selecting a tool the deactivate and activate methods seems to be called right after each other so maybe comparing a timestamp can be used to detect when a tool is re-activated.

                    My website: http://julia-christina-eneroth.se/

                    1 Reply Last reply Reply Quote 0
                    • fredo6F Offline
                      fredo6
                      last edited by

                      @eneroth3 said:

                      This seems like a documentation error. However when re-selecting a tool the deactivate and activate methods seems to be called right after each other so maybe comparing a timestamp can be used to detect when a tool is re-activated.

                      That's what I do, including for simulating a double-click on icon.
                      However, you cannot avoid the calls to activate() and deactivate(), just shortcut them.

                      I just realize that, should Trimble fix this issue, there could be some regression in my scripts, because I only test status 0.

                      Fredo

                      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