Extension Development Environment

Hello everyone,
I’m currently getting started with developing an extension. I’m new with Ruby, but I have a reasonable experience with other languages and tools.

I want to find out what others are using as a development environment for SU extensions as I find my current setup cumbersome compared to what I’m used to (JavaScript/TypeScript, nodeJS, .NET C#).

I currently use Visual Studio Code with a Ruby extension for code editing and I installed a SU extension so that I can attach to the SU process for debugging. This is fine but I find it very cumbersome that I have to reload SU each time I make a change to my files.

Also I do not see in any console any errors logged or some stack trace from a thrown exception when something does not work. And I’m having a bad time figuring it out why it does not work because I don’t get any error messages. I’m not sure if it fails silently and Ruby and/or SketchUp swallows exceptions.

What do you use and how do you usually work? How do you do debugging?

See if any of these hits offer any useful information.

Ruby is a dynamic coding language. You can change most any object dynamically at any time during Runtime. (Ie, you can redefine Modules, Classes, Methods, variable references, etc., any time. Think of Ruby code not as a file, but as being a big long string of text that is evaluated. This code text can be pasted into the console or loaded from a file.)

You may be trying to reload the file(s) using Kernel#require(). This method will only load a file once, then put it’s path into the $: (aka $LOADED_FEATURES ) array. Whenever this method runs, it will check the array and if the file has already been loaded, the method returns false without any action.

To force Ruby to reload a (unscrambled) file that was previously loaded, use Kernel#load() instead. This method does not check the $: array.

So if you had just changed a certain file whose path string reference is file, then at the console just type:

load file

Note that the global Kernel#load() is “picky” and wants the .rb file extension on the end of the file’s basename.

Also, these global Ruby methods cannot load scrambled (.rbs) or encrypted (.rbe) files, but you should just be developing in plain text (.rb) files anyway.


The API methods Sketchup::load() and Sketchup::require() have special coded subroutines to deal with scrambled (.rbs) or encrypted (.rbe) files, but usually just pass plain text .rb files to Kernel#require().

I use a mix of VSCode and RubyMine.
For RubyMine setup info have a look at the wiki in our examples and tutorials: https://github.com/SketchUp/sketchup-ruby-api-tutorials/wiki/RubyMine-Overview

I always throw in a utility method to my extensions to reload files without restarting SketchUp:

That being said if you change menus, toolbars or base classes you are forced to restart. I also recommend not putting logic into the blocks of menus and commands - because you usually have a load guard around those. Instead make the blocks call a separate method. Similar to this: https://github.com/thomthom/shadow-texture/blob/master/src/tt_shadow_texture/core.rb#L22

Do you have a reproducible example? This isn’t something I’ve observed. Note that you need to keep the Ruby Console open while the errors are thrown.

2 Likes

Also note that if your extension involves WebDialog or HtmlDialog objects, errors in javascript will be swallowed silently unless you explicitly code javascript to catch them.

Thanks for the reply :slight_smile:
The problem was that when I started to look for development plugins I installed this extension https://github.com/SketchUp/sketchup-developer-tools which I did not notice at the time that it was obsolete and I was using the development console which came with it. And nothing got logged in the console :blush:

I tried now with the built-in console from SU and errors and stack traces show up now. :slight_smile:

@slbaumgartner I haven’t had (yet) the need to integrate javascript but thanks for the heads up. I will keep that in mind.

@DanRathbun I reload my script with load <myScript.rb> but what I wanted is to find a way to do this automatically without me having to do it from the console every time. I will try out what @tt_su suggested. Thanks!

To hook an external IDE into a “live” SketchUp process, you need to use the SketchUp Debugger extension.

See for the SketchUp API index page:

Debugging, Testing and Tools sections.

I’ve been starting to catch JS errors and forwarding them back to Ruby so it’s easier to see when something goes wrong.
If you are using HtmlDialogs you can also right click in the dialog and open Chrome’s Developer Tools which is of great help while debugging.

Sorry about that - we’d not marked it as obsolete until a couple of days ago. (We’d kindof forgotten about that old project.)
As for a rich webdialog console, I can recommend @Aerilius console: https://github.com/Aerilius/sketchup-console-plus

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.