SketchUp Ruby-Debug


SuRDebug cluster

SuRDebug

SuRDebug is a Microsoft Windows GUI editor and shell surrounding Google SketchUp and the Ruby-Debug debugger.

It consists of wxSTEditor by John Labenski, Ruby-Debug debugger by Kent Sibilev, Google SketchUp, modifications and glue clode by Pecan Heber

How it Works

SuRDebug runs SketchUp as a sub process. It captures all I/O from RDebug (aka Ruby-Debug.rb) and the SketchUp Console by way of the standard I/O pipes. It interprets the captured data, presents it to the user by way of the editor, and drives the debugger from user editor actions .

Installation

SuRdebug requires a local installation of Ruby version 1.8.6. Download it from Ruby-lang.org . Download and install "The Ruby On Windows" Ruby 1.8.6 One-Click Installer about half way down the page.

Download SuRDebug from the Google Code respository, then unzip it to your Google SketchUp plugins folder. It consists of a folder named SuRDebug and a startup script named SuRDebugPlg.rb. Do not move files from .../Plugins/SuRDebug folder outside that folder. Only SuRDebugPlg.rb needs to be outside the .../Plugins/SuRDebug folder.

First run

Start SuRDebug from the SketchUp menu item "Plugins | SuRDebug | Run Debugger".

On the first run of SuRDebug, the program will attempt to find your SketchUp and Ruby installation directory. If it's not bright enough to succeed, it will present a file picker dialog to ask you for, and memorize, the location of those directories. If you are not already running Ruby library version 1.8.6 under SketchUp, the program will ask permission to backup the current Ruby lib running under SketchUp and install Ruby lib version 1.8.6.

If you find it necessary to restore the older version (usually 1.8.0) there is a menu item under "Plugins | SuRDebug | Restore Ruby Lib" to do so.

SuRDebug will close SketchUp and start the SuRDebug editor with SketchUp as a sub process. Check that the editor is not hidden behind SketchUp; especially if SketchUp is running in full screen mode.

Editor

You can find documentation for the wxSTEditor from the editors "Help | Editor.." menu entry. To change Ruby syntax highlighting preferences, read about "styles" in that documentation.

Debugger


Debugger menu


Debugger ToolBar
Run | Next Line | Step Into | Step Out | eXit

To invoke the debugger from within your Ruby script, use the " debugger(); " call statement . Without it, the debugger will never awaken and your script will run without interference from SuRDebug. Any number of " debugger(); " calls can be place anywhere within the executable path of your program.

Once the debugger is engaged (via the "debugger();" call) you can run/continue, step from line to line, step into a method or function, step out of a method or function, or exit the debugger from either the Debug menu or the toolbar.

For more information on debugger control, engage the debugger, then open the SuRDebug console from the "Debug | Console" menu item and type in "help" and/or "info".

Detailed information on running rdebug can be found at Debugging with ruby-debug. The information entitled "ruby-debug Command Reference" is useful for typing commands directly into the SuRDebug command console. Some commands (quit, exit, etc) will not work with SuRDebug as they are incompatible with SketchUp's embedded Ruby implementation.

The Console and SketchUp menu items toggle on/off the debugger console and the SketchUp subprocess.

Debug Menu Options

  • Auto Open Console. This opens the console whenever output is available from the debugger.
  • Inspect Selected Only. Data inspection occurs only when mouse hovers over marked text.

Breakpoints


The red circle in the margin above is a breakpoint. It is toggled by left clicking the mouse in the margin area just to the right of the line number. It can also be toggled from the editor's Debug menu.

Breakpoints can be set before the debugger Run command or after the debugger is engaged via the script " debugger(); " call.

Breakpoints are remembered across debugger invocations. You can clear them entirely with the editor's Debug menu or by eXiting the debugger.

The white triangle in the margin area above is the debugger current line marker. It indicates the next statement that will be executed by the debugger.

Examining data

The grey box in the image above is a Data Tooltip. It occurs when the debugger is engaged (via the " debugger(); " statement) and the mouse cursor is hovering over a variable. You can also examine data by typing in a "p yourVariable" command into the SuRDebug console.

SuRDebug Console

Your script puts and print statements will output to the SuRDebug console while the debugger is engaged. However, the SketchUp Ruby console will receive uncaught exceptions.

When the debugger is not engaged, SketchUp and it's console are usable. But because the standard I/O pipes are held by SuRDebug, "puts" and "print" entered into the SketchUp console will output to the SuRDebug console.

When the debugger is not engaged, commands typed into the SuRDebug console are not acted upon by SketchUp.

How to restore 1.8.0 manually

The original SketchUp Ruby lib is backed up to a file named ...\msvcrt-ruby180.dll in the SketchUp main executable folder. (usually c:\Program Files\Google\Google SketchUp 7\). To restore this lib, copy it to msvcrt-ruby18.dll in the same folder.

How to reset the memorized Ruby install location

The script ".../Plugins/SuRDebug/scripts/SetRubyInstallPath.rb" can be loaded into the Ruby console (or run from within the editor). SuRDebug memorizes this location in order to install/restore/verify the Ruby Lib used by SketchUp.

Instability of multiple runs

You can edit/change/rerun a script from the editor. However, Ruby is unable to unload a file once it's loaded. If you delete a variable reference in the editor, it's still known to Ruby until RDebug/SketchUp is restarted.

Some "bugs" are particularly hard to find when a file is run multiple times without exiting the debugger. For example, changing "class MyRoutine" to "module MyRoutine" causes a "is not a module" error because "class MyRoutine" is still known by Ruby.

To clean out the Ruby environment, simple "Quit Debugger" via the Debug menu or use the "X" icon from the Debugger tool bar.

Notes & Quirks

SketchUp can appear comatose while the debugger is engaged. It is not, however, disabled. It is waiting for the next command from the user by way of the editor or it is busy in your script.

Drag Scrolling

The editor and console can be scrolled by dragging the text with the depressed right mouse button. To change options for this feature see menu item " Help | DragScroll ".

Abbreviations

Abbreviations are text snippets that are replaced by blocks of code (templates). For example, type "ifei" (without quotes) into the editor, then press the Ctrl-J key combination. the abbreviation "ifei" will be replaced by:
 if (|)
elsif ()
else
end
The cursor will be place over the | (bar symbol). Define your own abbreviations via the main menu entry Preferences/Abbreviations...

KeyBinder

KeyBinder allow the user to assign up to three shortcut key combination to menu entries. Define your shortcuts via menu entry Preferences/KeyBinder...

KeyMacs

KeyMacs (Keyboard Macros)  enables Recording, Playback, and editing of keystroke macros.
KeyMacs Documentation