[Code] Tool ID Constants - Rev. 2
-
@thomthom said:
Hmm... interesting. But that's not the Tools. Just general references to commands.
What I had tried was looking through all the classes that existed. Thinking there'd be one for each tool as you'd do when you create a ruby tool. But there was nothing there either.My experience with those "constants" are that they are not always "constant". They're actually menu ids.
As long as the tool menu does not change, they'll work, but if someone inserts or changes the order of the menus, they shift around.
You can find all menu ids using EventRelay and the example script at http://code.google.com/p/eventrelay/wiki/EventRelay
# ---------------------------------- # Menus # ---------------------------------- def OnMenuSelected?(menuId, menuLabel) puts "MENU SELECTED MenuId?[#{menuId}] label[#{menuLabel}]" return ALLOW end #OnMenuSelected?
-
Ugh... I'm getting a bit tired now. I'm dealing with the ToolsObservers to work around some other malfunctioning observers. And now I have to a workaround for the workaround..? bleh...
Ok, tired ranting aside;
This event relay; you suggest using it to work out the IDs for the tools? Problem is that it won't work on Mac. Mac compatibility was the reason I'm trying to use the IDs since Mac truncates the tool names so you can't tell PolyTool apart from MoveTool or TextTool. -
Btw, how are native menu items shifted about? Can they be modified somehow? I thought that ruby menu items where added to the bottom of the menus. But you're saying they can affect the native menu items?
-
@thomthom said:
Btw, how are native menu items shifted about? Can they be modified somehow? I thought that ruby menu items where added to the bottom of the menus. But you're saying they can affect the native menu items?
When I wrote EventRelay, I noticed that I could not depend on menu items being constant.
I'm saying that native menu items shift about all on their own without the help of us script writers.
Eg., the Edit menu structure menu id's even share ids depending on what's selected before the user invokes the menu. Id 41002 can be "Delete Component" or "Flip along Groups Red" depending on the selection.
I'm suggesting that plugin menu id's are dynamic according to the order in which SketchUp finds them in the Plugin folder.
Insert a new plugin, your old plugin menu id may change.
I'm suggesting that the Tools menu id may change depending on whether I added someones C extension in the Tools menu.
I know it's frustrating and annoying. But that's the way (at least in windows) menu structures work.
Before EventRelay could translate a user command to a menu id, it had to ask, each time, the windows menu routines for its current menu id for a particular menu entry. It would have been so much easier had they been constant. No such luck, however.
-
@thomthom said:
Ugh... Mac compatibility was the reason I'm trying to use the IDs since Mac truncates the tool names so you can't tell PolyTool apart from MoveTool or TextTool.
Is it possible that the trucation is consistent enough that you could use a combination of the trucated name and the inspect id to create a hash to dynamically identify the tool?
Don't mean to insult your intelligence.
What does the trucation look like. I don't know, I don't have access to a mac.
If you had a map consisting of the SketchUp version number, the OS, the ordinary sequence of the Tools menu, the Ids of the ordinary menu, the inspect id of the tools, then you might be able to hack a hash of the Tool name.
If the user changes the Tools structure with a C extension or insertion, then they'll just have to punt. You still catch 99% of the users.
You should be able to get the Tool id from a "Tools observer" test script while physically observing your actions plus the report of the tool id.
Hope something of this helps.
-
Hi all!
Chris,
How do you use these CMD objects? -
I don't use them. But I was under the impression that SU registers these Constant variables everytime it starts. So they hold the correct ID, regardless of the OS or what have you. That might not be correct though. You guys are in quite the discussion about tool_Id's and such. I have not really needed to dig into them yet.
-
@pecan said:
What does the trucation look like. I don't know, I don't have access to a mac.
The first four characters are truncated.
I think the first think I need is to create a scenario where I can reliably cause the IDs to shift. Then I can work on and test a method to reliably identify the tools.
-
For a PC CMD_LINE returns 21020
so...
Sketchup.send_action(CMD_LINE)
runs the 'Line' command...
Don't know about Macs - any info ? Can a Mac user let us know what comes from typing CMD_LINE on their machines...
If it's possible to get 'numerical values' for commands beyond the base send_actions set on PC and Mac - even if they are different - then it becomes possible to do other stuff too - like closing the Outliner window during intensive script processing on PC and Mac to avoid BugSplats ??? -
On Mac:
> Sketchup;;CMD_LINE Error; #<NameError; (eval);8; uninitiated constant Sketchup;;CMD_LINE> (eval);8
-
Oh, sorry. Thought it belonged to the Sketchup namespace.
Here's the real deal:
> CMD_LINE 21020
Odd though, because on PC I got this:
Sketchup;;CMD_LINE (eval);131; warning; toplevel constant CMD_LINE referenced by Sketchup;;CMD_LINE 21020
Wonder why one system retuned a warning, and the other and error.
-
When I run
Sketchup.send_action(CMD_LINE)
from the ruby console, I get =>true
and it activates the line tool. and just typing in the constant I get
21020
as the return.My understanding of the constants was from Jim helping me figure out a way to determine if the user has hit the up arrow key. Since on a PC it returns on repsonse and on a Mac it returns another. But there is a constant called VK_UP that holds the correct ID if you are on a PC or if you are on a Mac. So instead of comparing the onkey event to a fixednum, I compare it to the VK_UP constant, and its always right on any platform.
I would hope that the CMD_ constants would be along the samelines of being initialized fresh each time SU starts and configured correctly for each OS.
Is that way off base?
-
When I tried tested some of the tool IDs and CMD_ constants they where identical on Mac and PC.
Advertisement