[Code] Tool ID Constants - Rev. 2

[Code] Tool ID Constants - Rev. 2

Postby thomthom » Sat Apr 04, 2009 7:13 pm

I couldn't find a list of tool IDs, so it'd be nice if people could add missing tools to the list. I've prepared the ones I've found in a list of constants associated to the ID's with a comment at the end with the string name.

Code: Select all
# Tool ID constants         # Tool Name
T_3D_TEXT            = 21013 # 3DTextTool
T_ARC                = 21065 # ArcTool
T_CAMERA_DOLLY       = 10523 # CameraDollyTool
T_CAMERA_ORBIT       = 10508 # CameraOrbitTool
T_CAMERA_PAN         = 10525 # CameraPanTool
T_CAMERA_POSITION    = 21169 # PositionCameraTool
T_CAMERA_WALK        = 10520 # CameraWalkTool
T_CAMERA_ZOOM        = 10509 # CameraZoomTool
T_CAMERA_ZOOM_WINDOW = 10526 # CameraZoomWindowTool
T_CIRCLE             = 21096 # CircleTool
T_COMPONENT          = 21013 # ComponentTool
T_COMPONENT_AXIS     = 21126 # ComponentCSTool
T_DIMENSION          = 21410 # DimensionTool
T_ERASE              = 21019 # EraseTool
T_FREEHAND           = 21031 # FreehandTool
T_FOLLOWME           = 21525 # ExtrudeTool
T_MODEL_AXIS         = 21126 # SketchCSTool
T_MOVE               = 21048 # MoveTool
T_MEASURE            = 21024 # MeasureTool
T_OFFSET             = 21100 # OffsetTool
T_PAINT              = 21074 # PaintTool
T_PASTE              = 21013 # PasteTool
T_POLYGON            = 21095 # PolyTool
T_POSITION_TEXTURE   = 21515 # PositionTextureTool
T_PUSHPULL           = 21041 # PushPullTool
T_PROTRACTOR         = 21057 # ProtractorTool
T_RECTANGLE          = 21094 # RectangleTool
T_ROTATE             = 21129 # RotateTool
T_SCALE              = 21236 # ScaleTool
T_SELECTION          = 21022 # SelectionTool
T_SECTIONCUT         = 21337 # SectionPlaneTool
T_LINE               = 21020 # SketchTool
T_TEXT               = 21405 # TextTool
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Code] Tool ID Constants - Rev. 2

Postby Chris Fullmer » Sat Apr 04, 2009 7:49 pm

Have you looked at

Object.constants for all constants and

Object.constants.grep(/CMD/).join(', ')

for a list of reigstered CMD or command constants? Maybe that's not what your looking for, but there you go in case its helpful. Jim showed me that.

Just the constants prefixed with CMD are:

Code: Select all
CMD_OPEN, CMD_ORBIT, CMD_SHOWGUIDES, CMD_VIEW_FRONT, CMD_SCALE, CMD_PAGE_NEW, CMD_TEXTURED, CMD_ARC, CMD_SAVE, CMD_DOLLY, CMD_SELECTION_ZOOM_EXT, CMD_VIEW_RIGHT, CMD_OFFSET, CMD_PAGE_DELETE, CMD_TRANSPARENT, CMD_POLYGON, CMD_CUT, CMD_ZOOM, CMD_DISPLAY_FOV, CMD_VIEW_BACK, CMD_MEASURE, CMD_PAGE_UPDATE, CMD_WALK, CMD_FREEHAND, CMD_COPY, CMD_ZOOM_WINDOW, CMD_SELECT, CMD_VIEW_LEFT, CMD_PROTRACTOR, CMD_PAGE_NEXT, CMD_PAN, CMD_PUSHPULL, CMD_PASTE, CMD_ZOOM_EXTENTS, CMD_PAINT, CMD_VIEW_BOTTOM, CMD_SKETCHCS, CMD_PAGE_PREVIOUS, CMD_MAKE_COMPONENT, CMD_TEXT, CMD_DELETE, CMD_CAMERA_UNDO, CMD_ERASE, CMD_VIEW_PERSPECTIVE, CMD_SECTION, CMD_RUBY_CONSOLE, CMD_DIMENSION, CMD_MOVE, CMD_UNDO, CMD_WIREFRAME, CMD_RECTANGLE, CMD_POSITION_CAMERA, CMD_DRAWOUTLINES, CMD_SKETCHAXES, CMD_VIEW_ISO, CMD_ROTATE, CMD_REDO, CMD_HIDDENLINE, CMD_LINE, CMD_NEW, CMD_DRAWCUTS, CMD_SHOWHIDDEN, CMD_VIEW_TOP, CMD_EXTRUDE, CMD_PRINT, CMD_SHADED, CMD_CIRCLE
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Code] Tool ID Constants - Rev. 2

Postby thomthom » Sat Apr 04, 2009 8:41 pm

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.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Code] Tool ID Constants - Rev. 2

Postby pecan » Sat Apr 04, 2009 10:35 pm

thomthom wrote: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

Code: Select all
# ----------------------------------
# Menus
# ----------------------------------
def OnMenuSelected?(menuId, menuLabel)

    puts "MENU SELECTED MenuId?[#{menuId}] label[#{menuLabel}]"
    return ALLOW

end #OnMenuSelected?
0

pecan 
 

Re: [Code] Tool ID Constants - Rev. 2

Postby thomthom » Sun Apr 05, 2009 12:00 am

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.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Code] Tool ID Constants - Rev. 2

Postby thomthom » Sun Apr 05, 2009 12:02 am

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?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Code] Tool ID Constants - Rev. 2

Postby pecan » Mon Apr 06, 2009 4:09 am

thomthom wrote: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.
0

pecan 
 

Re: [Code] Tool ID Constants - Rev. 2

Postby pecan » Mon Apr 06, 2009 4:31 am

thomthom wrote: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.
0

pecan 
 

Re: [Code] Tool ID Constants - Rev. 2

Postby Matt666 » Mon Apr 06, 2009 7:46 am

Hi all!
Chris,
How do you use these CMD objects?
0
Frenglish at its best !
My scripts

Matt666 
 

Re: [Code] Tool ID Constants - Rev. 2

Postby Chris Fullmer » Mon Apr 06, 2009 7:56 am

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.
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Code] Tool ID Constants - Rev. 2

Postby thomthom » Mon Apr 06, 2009 9:50 am

pecan wrote: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.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Code] Tool ID Constants - Rev. 2

Postby TIG » Mon Apr 06, 2009 9:55 am

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 ???
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Code] Tool ID Constants - Rev. 2

Postby thomthom » Mon Apr 06, 2009 10:05 am

On Mac:
Code: Select all
> Sketchup::CMD_LINE
Error: #<NameError: (eval):8: uninitiated constant Sketchup::CMD_LINE>
(eval):8
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Code] Tool ID Constants - Rev. 2

Postby thomthom » Mon Apr 06, 2009 10:09 am

Oh, sorry. Thought it belonged to the Sketchup namespace.

Here's the real deal:
Code: Select all
> CMD_LINE
21020


Odd though, because on PC I got this:
Code: Select all
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.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Code] Tool ID Constants - Rev. 2

Postby Chris Fullmer » Mon Apr 06, 2009 5:24 pm

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?
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Code] Tool ID Constants - Rev. 2

Postby thomthom » Mon Apr 06, 2009 5:54 pm

When I tried tested some of the tool IDs and CMD_ constants they where identical on Mac and PC.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: No registered users and 17 guests

Visit our sponsors: