Extended Shortcuts via Ruby Script


#1

Hello,

I’m wondering if there is a way to extend certain Sketchup shortcut commands with Ruby Script.

Most CAD programs I have used had a basic shortcut parameter file similar to Sketchup’s that was capable of executing a single command.

Additionally multiple commands could be executed via its various programming languages.

While not a developer or expert programmer, it was relatively easy for me to setup a custom startup file that would autoload small timesaving routines as well as complex programs as needed. Once loaded, the program could run with a single keystroke, a word or whatever it was named. Like SU the program could also have a menu name or icon button associated with it.

If such a program could be written with Ruby Script, I would use it to accomplish certain tasks without using modifier Keys, eg. ctrl+X, Shift=Y, etc. I prefer to keep shortcuts as simple as possible. I have two hands but one is usually on the Mouse the other either typing a single keystroke shortcut command or using it for my 3D Mouse.

I would first attempt to perhaps expand some commands such as expanded zoom functionality, Maybe a separate Copy, Copy multiple, without using Move and holding the ctrl key to copy. Maybe a combined copy + rotate.

A startup type script might do whatever needed but the main purpose would be to extend Shortcut keystrokes with an additional method beyond what is currently available with SU’s shortcut file and its limitations and restrictions.

I might attempt to try writing a script if anyone here thinks it is feasible using Ruby. A startup type file of this type would probably be first on my wish list for SU 2019 if it is possible.

Any ideas, comments or thoughts on this thread would be appreciated.


#2

Please expound on this some more. What limitations and restrictions are you encountering?

You can change the default shortcut for any command, including to use or not use modifier keys.

You can’t change how a Tool responds to modifier keys once it is active (e.g. you can’t use something different than ctrl to tell the eraser tool to soften an edge) but I don’t think that’s what you mean.

Also, there is no need (or ability) for a startup Ruby script to set keyboard shortcuts. The preferences window lets you assign your own and will remember them for the next SketchUp session.


#3

I probably use SU now more than any other CAD program these days. I have always customized CAD to my liking. I got away from SU for quite a while since my office went heavily into BIM. Now that I’m mostly retired I have had more time to work with SU on a fairly regular basis. SU has evolved tremendously and now has many more useful extensions than the Pro version I first purchased in 2004. The same was true of 2D CAD. It worked out of the box but worked, at least for me, much better with user and 3rd party developer customization, much of which was later incorporated into the core program.

Extensions and customization can fill in many gaps in programs. Some I may use a lot and some only when needed. Some of the simplest custom commands can be huge time savers. Having flexibility I believe is important even if only some or only a few users choose to use all of what may or may not be available.

I fully understand that SU is not the same as other CAD or BIM programs I may use. I use several programs. I also use Photoshop but not on an everyday basis. Memorizing all its shortcuts is probably the most efficient way to use it but like SU remembering every shortcut is not something every user should be expected to memorize in order to use it. I particularly do not like having to use modifier keys or multiple keystrokes to execute a command I use often.

I use the SU copy command a lot (I don’t mean Copy/Paste, ctrl+C, ctrl+P). In my opinion, SU’s copy method deserves its own command. It should NOT have to work by using the Move tool while holding down the CTRL key. There is no way I know to make a shortcut for Move, sub command COPY or copy multiple.

There is no way to execute any chain of commands via SU’s shortcuts. It does seem possible however by writing a program to do so. It does not have to be done with a startup routine available in most 2D CAD programs but it might be convenient if it could be done. Sometimes demand loading is preferable to other ways of loading SU’s extensions. There is actually an extension that does this that I find useful.

I may not have the same needs as everyone else. The extensions I use such as TIG’s Mirror command can be done with SU’s scale command but I find mirroring TIG’s way(like how most other CAD programs I am familiar with) is superior to SU’s way.


#4

SU does’t have macro’s in the traditional lisp way, but can combine SU calls with System event to mimic some combinations…

I only use mac’s and I made a AutoCad type ‘MoveCopy’ plugin for another OS X user recently…

he then added a single key shortcut to activate my command…

it’s a very niche area with little or no capital reward…

it may be best to learn some ruby and roll your own…

john


#5

Can you distill your post down to the essential question? (Not everyone wants to read a novel.)

No, you cannot assign keyboard shortcuts through an extension, this would allow extensions to conflict with each other (but you can make the extension have a menu item, and then the user can assign a shortcut to the menu item).

Yes, you can extend SketchUp using the Ruby API, and automate tasks by combining several actions into one. But this only works for single-step actions that have a Ruby command. You cannot break down multi-step interactive tools, especially from native tools that don’t consist of Ruby commands (like array copy as part of the Move tool).


#6

John,
You get what I was trying to convey. I didn’t mention any specific “other " program(s)” but the real power of that program is its Lisp subset and the customization capabilities possible.

Al Hart did build a separate copy command for SU. It is part of a suite I had that I believe he still sells. It worked okay but I didn’t find it to save much time since (as I remember) it was dialog box driven and I don’t think it could be linked to a shortcut key.

I may give Ruby a try on my own. I know Autolisp (better than any other language), some VB, Python and some C++. I don’t see too much future for Ruby beyond SU but what the hay, I have the time.

What I want to do may prove to be impractical or not useful to all but probably not impossible.

Thx!


#7

EDIT: I see in your 2nd and 3rd posts you’re not a newb, so these thoughts are also for other readers that may be new to these concepts. …

Just FYI, … many native tools allow you to type xNumber in the Measurements (Value Control Box) then ENTER, after a command to repeat multiple times.

You do not need to hold CTRL key to copy. It is a toggle switch, … just tap CTRL once to toggle copy ON (you’ll see the tool cursor change to indicate copy is ON when the cursor has a + sign. This is normal for many native tools.) When copy is ON, tap CTRL to switch it off. (The cursor returns to normal.)

Note: The native Rotate tool does this already. Again use the CTRL toggle to make one copy, then type say x3 + ENTER to make a total of 3 copies (including the first but not the original.) You’d then have a radial array of 4 objects, spaced by the angle used to make the first copy.

You cannot extend or change the behavior of native tools, … BUT you can write new Ruby tools that mimic their behavior, or do the same task in a different workflow. However the learning curve is steep and time consuming.

SketchUp’s shortcuts (aka, keyboard accelerators) are not defined in a script file. The assignments are now kept in a JSON preferences file. (In previous Windows editions they were kept in the registry.) Assignments must be made manually. They are considered an enduser action and are not exposed via the APIs for setting, but can be read.

Shortcuts must point at menu items (UI::Command objects.) The menu commands for native tools are linked to native C++ functions that are not exposed to any APIs for editing. (They can be fired with send action calls however.)

The menu commands for your custom Ruby tools would point at your Ruby method(s) within your plugin module. (Please be aware that Ruby tools are event-driven code objects and not sequential macro scripts.)

A lot of stuff is feasible. Start by playing with the Ruby Console, doing simple things first. Move slowly on to more and more complex tasks.

However, you need to realize that SketchUp was designed purposely not to have the same old CAD command type interface. Think of all those ACAD clones that have come and gone. SketchUp survives because it never tried to be a clone, and the developers will never try to make it be one.

We always advise users coming from traditional CAD to first learn and master how the SketchUp interface works before attempting to change it or write custom tools. Then we advise to look for plugins and extensions that are already available before spending time programming. Lastly, use the work of others as examples, and study the examples that the SketchUp Team has posted to their Extension Warehouse page.


#8

Dan,

Your reply is detailed and informative. You are right I am not a newbie to SU, CAD or BIM but your comments are full of common sense to most SU users. So I don’t get accused of novel writing by a few snobs here I’ll just say thanks for your good advice. I may play with Ruby a little but I doubt my efforts will amount to much that is not native SU or already an extension.