Retrive the tool selected before launching my plugin
-
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 :
- I select the tool (circle tool for example), a component or something else...
- I launch the plugin
- I select my 3 points
- The center is draw and the circle tool is activate on the center (or component placed here).
example :

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 ?
-
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 callSketchup.send_actionbut
you have to have a action string hash, because
some of then differ from the names returned by
theTools.active_tool_namemethod.See these posts for a lookup hash examples:
http://forums.sketchucation.com/viewtopic.php?t=18124In this one (below) you'd have to cut & paste the hash into your OWN namespace:
(Do not distibute it so that it modifys theSketchup::Toolsclass. 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=36177Also be aware that if the previous tool was a custom tool, then the
Tools.active_tool_namemethod 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,) toSketchup.send_action(), but not on Mac/OSX. -
You can also use a Tools observer subclass:
https://developers.google.com/sketchup/docs/ourdoc/toolsobserver -
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 -
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 theactive_tool_idis 0 until some valid tool is selected.In addition the
push_tool()method only accepts aUI::Toolclass object (or the API dictionary says that is what it expects. But since there really is noUI::Toolprotoclass, 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 returnstrueanyway. -
I'm gonna test it right now

-
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
-
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 ?
-
@njeremy2 said:
Maybe if I can retrive the ID with
@id = @tools.active_tool_idandSketchup.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. -
@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.
-
@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 !

-
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 !!
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 LoginAdvertisement