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?
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().
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.
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.
@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!
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.