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 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:
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.
Thanks for the reply
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
I tried now with the built-in console from SU and errors and stack traces show up now.
@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.