When do Tools.active_tool_id return 0 ?
-
http://code.google.com/apis/sketchup/docs/ourdoc/tools.html#active_tool_name
@unknownuser said:
Tools.active_tool_name
The active_tool_name method is used to retrieve the active tool's name.NOTE: Calling active_tool_name on an empty Tools collection might cause a crash. Before calling this method, it is important to check whether or not the Tools collection is empty. The Tools collection is empty if the method .active_tool_id returns zero.
Under what scenario does
Tool.active_tool_id
return 0 ? -
Two I know of offhand:
(1) Just after Sketchup starts, there is only 1 tool on the stack. If a script uses Tools.pop_tool the Tools.active_tool_id should return 0. This is the scenario that led me to first report the Tools.active_tool_name BugSplat! bug in the beta forum.
(2) The SetNorth native tool is bugged in that it does not properly reset the previous tool on the stack when it completes. So the active_tood_id() is 0 and calling active_tool_name() causes a BugSplat! (This is why I had to patch Jim's old version of the CustomToolbars.)
I "think" I noticed a few other situations when using some feature (like a dialog,) but can't remember.
I would suggest implementing a messagebox in a ToolsObserver that pops up anytime active_tool_id is 0, so we can compile a better list. -
pop_tool can pop tools off the stack that wheren't pushed?
-
@thomthom said:
pop_tool can pop tools off the stack that wheren't pushed?
Yes... from my reproduce steps in Bug Report SU-0493:
` %(#0000BF)[1) Start SU (the SketchTool is active.)
2) open the Console, and type:
3) Sketchup.active_model.tools.pop_tool- at this point the Sketchup::Tools collection is empty
- in the Console, and type:
Sketchup.active_model.tools.active_tool_name
... and SPLAT!
Note, that at this point, if you instead type:
Sketchup.active_model.tools.active_tool_id0 is returned]`
Simone has proposed that the active_tool_name() method be fixed to return an empty string when active_tool_id() retruns 0. (internal bug 3424904)
I also proposed an query method in that report:
class Sketchup;;Tools def empty? return self.active_tool_id==0 end end
AND that module Enumerable be mixed into class Sketchup::Tools
(I tried it myself on the Ruby-side, but was not successful, perhaps because it's a C++ collection.) I noted that there was no way to get the size of a tools instance. -
By the way, it seems that, on MAC, active_tool_name may return a truncated text (for instance "ctionTool" for SelectionTool, or "angle" for Rectangle).
Fredo
-
@unknownuser said:
By the way, it seems that, on MAC, active_tool_name may return a truncated text (for instance "ctionTool" for SelectionTool, or "angle" for Rectangle).
Yes... this is the reason we are treating this issue. We need to use the tool_id rather than the tool_name to work around the Mac bug.
In SU8 Google did fix the Mac tool name bug for the ToolsObserver, but forgot to fix the Tools collection active_tool_name() method.
Advertisement