[Code] Tool ID Constants - Rev. 2
-
@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