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

Tool.onCancel - Reselect tool?

Scheduled Pinned Locked Moved Developers' Forum
9 Posts 5 Posters 1.1k 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.
  • T Offline
    thomthom
    last edited by 12 Sept 2012, 16:35

    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
    • T Offline
      thomthom
      last edited by 12 Sept 2012, 16:41

      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
      • F Offline
        fredo6
        last edited by 12 Sept 2012, 18:25

        @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 12 Sept 2012, 19:52

          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
          • T Offline
            thomthom
            last edited by 12 Sept 2012, 20:24

            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
            • D Offline
              Dan Rathbun
              last edited by 13 Sept 2012, 13:54

              πŸ‘Ώ (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
              • T Offline
                thomthom
                last edited by 13 Sept 2012, 13:58

                @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
                • E Offline
                  eneroth3
                  last edited by 23 Mar 2017, 14:38

                  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
                  • F Offline
                    fredo6
                    last edited by 23 Mar 2017, 16:30

                    @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