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!
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Retrive the tool selected before launching my plugin

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 3 Posters 571 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.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by

      You can also use a Tools observer subclass:
      https://developers.google.com/sketchup/docs/ourdoc/toolsobserver

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • K Offline
        kwalkerman
        last edited by

        I think what you want to do is re-select the tool the user originally had selected when they activated your plugin. To do it:

        original_tool = Sketchup.active_model.tools.pop_tool
        
        myTool.activate
        
        # Now execute your code.  When you're finished, maybe in the tool's deactivate method;
        
        Sketchup.active_model.tools.push original_tool
        

        --
        Karen

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          Karen that will not work (presently) as the pop_tool() method is bugged. It returns boolean, not the tool object. (I think I entered an API bug for this.) It can also set up the situation where the tool stack is empty if there was only 1 tool in it, and the active_tool_id is 0 until some valid tool is selected.

          In addition the push_tool() method only accepts a UI::Tool class object (or the API dictionary says that is what it expects. But since there really is no UI::Tool protoclass, does the method do any typechecking at all?)

          Apparently not as:
          Sketchup.active_model.tools.push_tool 21013
          Does not select the Component Placement tool, but it returns true anyway.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • N Offline
            njeremy2
            last edited by

            I'm gonna test it right now πŸ˜„

            1 Reply Last reply Reply Quote 0
            • N Offline
              njeremy2
              last edited by

              Hmmmmmmm
              I a little bit hard to use ...

              To begin easily, I made a plugin which display the name of selected tool
              I will show you the progress πŸ˜‰

              1 Reply Last reply Reply Quote 0
              • N Offline
                njeremy2
                last edited by

                Hmmm, it's little bit weird :

                When I retrive the ID of the tool with your solution, I obtain an ID number but when I launch a second time the plugin, I have a second ID number. WHY ??? πŸ˜’

                But, I've try this:

                @model = Sketchup.active_model
                @tools = @model.tools
                @name = @tools.active_tool_name
                @name2 = "select#{@name};"
                
                Sketchup.send_action "#{@name2}"
                

                It works for most of tools except for LineTool (it's called "SketchTool" instead of "Linetool"), polygon, axis tool.

                Maybe if I can retrive the ID with "@id = @tools.active_tool_id" and "Sketchup.send_action (@id)" it should be better but how do we do ?

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  @njeremy2 said:

                  Maybe if I can retrive the ID with @id = @tools.active_tool_id and Sketchup.send_action (@id) it should be better but how do we do ?

                  1) Yes you CAN use id, but ONLY on PC/Windows.

                  It does NOT (currently) work for Mac/OSX.
                  2) NEVER put a space between the method name and the ( of it's argument list.

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    @njeremy2 said:

                    It works for most of tools except for LineTool (it's called "SketchTool" instead of "Linetool"), polygon, axis tool.

                    We know. This is why I told you (in post http://forums.sketchucation.com/posting.php?mode=quote&f=180&p=405232#pr404805 ) that you need a send action lookup hash.

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • N Offline
                      njeremy2
                      last edited by

                      @dan rathbun said:

                      @njeremy2 said:

                      It works for most of tools except for LineTool (it's called "SketchTool" instead of "Linetool"), polygon, axis tool.

                      We know. This is why I told you (in post http://forums.sketchucation.com/posting.php?mode=quote&f=180&p=405232#pr404805 ) that you need a send action lookup hash.

                      ahhh ok !! lol sorry !

                      You write too much text and google translation doesn't translate very well ! πŸ˜„

                      1 Reply Last reply Reply Quote 0
                      • N Offline
                        njeremy2
                        last edited by

                        Now, I'm using name to identify the tool

                        For this moment it works πŸ‘

                        I don't understand the ID method, maybe when I feel ill at ease with ruby, I can understand how it works

                        Thank you Dan and Karen !!

                        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