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 573 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.
    • N Offline
      njeremy2
      last edited by

      Hello everyone ! β˜€ (35Β°C in South of France)

      Today I have a new enigma, I need to create a plugin which allow us to choose 3 points and find the center of the them.
      This part is done but for this plugin I need more.

      My plugin should work like that :

      1. I select the tool (circle tool for example), a component or something else...
      2. I launch the plugin
      3. I select my 3 points
      4. The center is draw and the circle tool is activate on the center (or component placed here).

      example :

      http://img39.imageshack.us/img39/275/79886999.jpg

      I search on Google Sketchup API and automatic sketchup PDF, I use Sketchup.send_action "selectCircleTool:" for activate the plugin circle tool.

      I should retrive the tool before lauching the plugin, I try this :

      tools = Sketchup.active_model.tools
      Sketchup.send_action "#{tools}"
      

      or

      tools = Sketchup.active_model.select_tool nil
      Sketchup.send_action "#{tools}"
      

      I succeed how to pick a component to put in the center but I don't know how to retrieve a tool selected before
      Someone can help me ? πŸ˜„

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

        tools = Sketchup.active_model.tools
        current_tool_id = tools.active_tool_id
        # may be 0 if no active tool, so watch out!
        # this might happen just after SketchUp starts
        
        # you can get active tool name IF, and only IF
        # active_tool_id != 0. If it is 0 and you call
        # active_tool_name, you cause a BugSplat! crash.
        current_tool_name =( tools.active_tool_id != 0 ? tools.active_tool_name ; "SelectionTool" )
        

        Then set your custom tool as the current tool,
        when done you can use the previous id or name
        to call Sketchup.send_action but
        you have to have a action string hash, because
        some of then differ from the names returned by
        the Tools.active_tool_name method.

        See these posts for a lookup hash examples:
        http://forums.sketchucation.com/viewtopic.php?t=18124

        In this one (below) you'd have to cut & paste the hash into your OWN namespace:
        (Do not distibute it so that it modifys the Sketchup::Tools class. It's an example for Google/Trimble only, of how the API class might be modified in the future.)
        http://forums.sketchucation.com/viewtopic.php?f=315&t=36177

        Also be aware that if the previous tool was a custom tool, then the Tools.active_tool_name method ALWAYS returns the string "RubyTool".
        IF this happens you can call the previous tool on Windows by passing the tool id as an integer argument (not a string,) to Sketchup.send_action(), but not on Mac/OSX.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • 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