Ruby Hotkeys Plugin?
-
use the Sketchup.send_action method.
-
@dan rathbun said:
use the Sketchup.send_action method.
I know some of numeric values applied to “Sketchup.send_action( )"
For example, some of them:
10527: "Shift+Ctrl+E"
10526: "Shift+Ctrl+W"
-7892: "Ctrl+Y"
21101: "Ctrl+A"
21065: "A"
21096: "C"
21019: "E"
21074: "B"And so on…
But I don’t know the numeric values for the key combination, for example, "Shift+Ctrl+A" or "Shift+Ctrl+B" or "Shift+Ctrl+C", etc.
Where can I find numeric values for these (and similar) key combination?
-
@tig said:
BUT why would you want to do this ??
I will answer your question. But, with my “excellent knowledge of English”, I'll be a long time to formulate my ideas.
-
@sergey2402 said:
Where can I find numeric values for these (and similar) key combination?
Numeric arguments only work on Windows, not on Apple Mac.
Concentrate on the command (not the key combos,) and use the string arguments for send_action.
Example: Ctrl+Shift+W = Camera Zoom Window, so:
Sketchup.send_action("selectZoomWindowTool:")
Any user can change the shortcut key combos for commands.
-
@dan rathbun said:
Numeric arguments only work on Windows, not on Apple Mac.
Concentrate on the command (not the key combos,) and use the string arguments for send_action.
Example: Ctrl+Shift+W = Camera Zoom Window, so:
Sketchup.send_action("selectZoomWindowTool:")
Any user can change the shortcut key combos for commands.
Thank you very much for you paid me attention. But my question is different.
Where can I find numeric values for these ("Shift+Ctrl+A" or "Shift+Ctrl+B" or "Shift+Ctrl+C") key combination? -
@sergey2402 said:
In a nutshell - the ultimate goal to create a Ruby script called "hotkeys buttons on the toolbar"
I mean, hotkeys are not built into SketchUp. I mean user-defined any hotkeys for any plugins.?
You can define hotkeys for any menu or toolbar element - that include those the belongs to ruby scripts? -
@thomthom said:
?
You can define hotkeys for any menu or toolbar element - that include those the belongs to ruby scripts?Sorry, I do not understand. That was the question? Or was it your help?
Of course, my English is "excellent", but I understand it is very bad. -
@tig said:
BUT why would you want to do this ??
In a nutshell - the ultimate goal to create a Ruby script called "hotkeys buttons (or icons) on the toolbar"
I mean, hotkeys are not built into SketchUp. I mean user-defined any hotkeys for any plugins. -
Window > Preferences > Shortcuts
Filter for the tool/ruby required.
Set shortcut key[s] to it.
Note that some items only appear in the list if there is a suitable selection - e.g. to shortcut to 'Reverse' face as seen in the context-menu, you must first select a face then open Preferences - if no face is selected then the 'Reverse' doesn't appear in the available items to shortcut to...
Provided your plugin has some sort of menu presence you can shortcut to it by 'name'... -
Serge, you are talking about Windows Automation with Ruby.
The "Ruby Way" is to use the Ruby Win32ole library. (Search Ruby Gems about using Ruby libraries in SketchUp-Ruby.)
Alternative to win32ole, some plugins use the WShell.SendKeys() from a .vbs script to do the automation. (I use this in Save as Previous Version.) Windows Powershell can also use the SendKeys function to automate Windows.
There is no "perfect" solution.
-
@jim said:
Serge, you are talking about Windows Automation with Ruby.
Unfortunately, for me it is too difficult. I'm just a civil engineer, not a programmer. I really like SketchUp and I found it very useful. I just want a little to tweak it for me...
-
In the menu Window > Preferences > Shortcuts I redefined the letter "H" from the “Camera/Pan” to plugin “Pipe Along Path”.
I drew the lines, selected them and pressed on the keyboard the letter “H”.
Plugin “Pipe Along Path” been executed. BINGO!I drew the lines again, selected them and run Window > Ruby Console.
In the Ruby console I wrote a string “Sketchup.send_action 10523” and pressed Enter
(I know - the value of 10 523 corresponds to the letter “H”)And what I see as a result?
I see a HAND (Camera/Pan)!!!
What nonsense is going on?
-
What makes you think that 'Sketchup.send_action 10523' is an 'H' ???
10523 == 'Moves the camera viewpoint while maintaining view direction' [PC only!!]
Remapping a shortcut key has no connection whatsoever with that key's previously linked command ???
You've simply changed 'H' to be the shortcut key for 'PipeAlongPath'...
The 'send_action' still calls the fixed linked-command!
IF you want to use the 'H' to execute its linked-command use a Wscript or similar key-emulator BUT, oh BUT, why are you trying to do this weirdness ?????
Why not simply invoke PipeAlongPath directly ??? -
Yes. You are right. Just I have not checked the information given to me
-
I know about the key-emulators.
But I want to achieve this result by means Ruby and Sketchup. Is it not possible? -
@sergey2402 said:
I know about the key-emulators.
But I want to achieve this result by means Ruby and Sketchup. Is it not possible?It is possible to send key-strokes to a PC window which will invoke the linked shortcut - as explained in earlier posts - using tools like Wscript etc...
BUT my question is why do you want to do this ?
You can invoke another tool within your own tool by using a reference to that tool rather than needing to shortcut key to it ??
SO for example if your own tools need to change to run 'PipeAlongPath' at some point then simply add the test and thenpipe_along_path()
[it's an old script not well written!] or if you want to add a 'WorkPlane' you'd useWorkPlane.new()
or some tools like my 'TextureRotate' tool will either run as a tool giving a dialog for you to give an angle... BUT if called from within another script with an appropriately [pre]selected face and an angle they'll run as part of the second tool's code... e.g.TextureTools::Rotate.new()
opens the dialog [assuming one face is selected]...
BUT if you were to have several faces 'selected' in your own tool you can iterate through the array of faces and then clear the model selection and add each face in turn, usingTextureTools::Rotate.new(90.0)
to rotate the texture of every face 90 degrees - on completion you are still in your tool and can do other things as desired...
Get each appropriate activation code from the third=party tool's menu definitions or help notes etc...
You might also want to 'require' the third-party scripts to ensure they are loading...
You can't readily jump back into your code if the new tool exits it because it's not written for 'inclusion' [unlike TextureRotate which was!]... however, you can use convoluted observers to check for tool-changes etc and re-run your code from a point after the other tool is done ? ...
However, an easier way if the third-party tool doesn't favor 'inclusion' would be to write your own methods to make say a 'def pipe_along_path(radi,rado,path)
' method within your own tool and invoke that methods as needed, passing the radii and array of path edges etc - you simply find the parts of the code in any third-party tool's that you wish to 'borrow' and rewrite them as needed - always remembering to credit other authors where appropriate... -
@tig said:
... BUT my question is why do you want to do this ? ...
OK. I will tell you a little story.
My friend (F) said to me (M) recently:
(F) I have on the toolbar buttons of SketchUp at the top 4 rows of icons , bottom - 1 row, left 2 columns and right 1 column
I do not need so much.
In these plugins I use only one or two icons (maybe three - but no more).
Why do I need to keep unwanted toolbar icon?
I know - it is possible to see the text of each script, find the command that it does and write a new script for the icon on the toolbar for this command.
But I'm not a programmer. And I can’t and I don’t want find at the other people's scripts rows with those commands.
And I do not know how to write Ruby scripts.(M) And what do you want from me?
(F) I can define in SketchUp hotkeys for commands necessary to me.
And you should write a new Ruby script that would be emulated press these hot keys (such as "Shift+Ctrl+A.rb" and "Shift+Ctrl+B.rb" and "Shift+Ctrl+C.rb", ect, but not "Shift+Ctrl+E.rb" or “H.rb” and so on, because those are internal commands of SketchUp). And these new scripts must be in the form of an icons on the toolbar.(M) BUT why would you want to do this??
(F) Then I can assign hotkeys (to plugins, that I need) and leave them on the toolbar (your new icon), and the all unwanted icons (top 4 rows, bottom 1 row, etc) I will hide.
And the lines in your new scripts (e.g. cmd.tooltip = "Shift + Ctrl + A") I'll be able to change myself by e.g. cmd.tooltip = "run plugin X". And the icons in your new folder "My Icons" I'll be able to change myself, too.(M) And then what?
(F) 1. And then - on my toolbar is only one row with the required icons.
2. And then - when I want I can quickly redefine hotkeys for the other plugins (if there is a newer or better version from another programmer).
3. And then - I can have icons for plugins that do not have icons.
4. And then - any user (not programmer) will be able very easy to create your personal toolbar.
5. And so on...(M) Well, I'll ask on the forum sketchucation.com - is it possible to do so?
And so I ask - is it possible to do so?
-
I think you are approaching this from the wrong direction...
You are really looking to make a customized toolbar.
This has already been done.
You can set up a toolbar by a global reference [$] and add buttons to it as needed at startup, even from another script...
Provided you read [usually] the final parts of a .rb script for the toolbar making code you can see how to add the 'commands' to a toolbar - including your own.
If you want to make a shortcut key-combo to a tool it's straightforward provided the tool has a menu item etc that you can link to - including your own which can just be a list of tools in a submenu...
To disable a tool's own menu/toolbar etc put # in front of the relevant line[s] or =begin...=end for larger blocks of code. The tool's code will still load but without a menu/toolbar until used in your own menu/toolbar...
I'm still not sure what the advantages are to you in doing it in this other seemingly excessively convoluted manner, which could be possible [OS dependent] but of less benefit that the effort warrants... -
Thank you. I will tell my friend - it's impossible. Forget about it.
Advertisement