Retrive the tool selected before launching my plugin
-
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_id
is 0 until some valid tool is selected.In addition the
push_tool()
method only accepts aUI::Tool
class object (or the API dictionary says that is what it expects. But since there really is noUI::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 returnstrue
anyway. -
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_id
andSketchup.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 !!
Advertisement