Debugging a complicated plugin can be challenging, particularly when it involves WebDialogs, etc. So, SketchApps augments SketchUp's native debugging tools.


The Ruby Console is SketchUp's primary debugging tool. It captures standard output (eg, puts), tracebacks, etc. To make console logging more convenient and informative, SketchApps provides some convenience methods:


Hanging .inspect on the end of every object is tedious and the output format needs some love. So, SketchApps provides a tiny wrapper method (i), used as:

puts 'object=' + i(object)


The PF_Logger class provides conditional logging (based on the logging level set in $HOME/.sa_config) and contextual information. It writes to both the console log and $HOME/.sa_log_file, described below)

The SketchApps source code is the best place to find usage examples, but here's a code snippet to whet your appetite:

def some_method
  foo = [ 'bar', 42, :baz, true ]

  @pf.log.debug [ 'foo.size=' + i(foo.size),
                  'foo='      + i(foo) ] #T

  @pf.log.warn 'foo[1]=' + i(foo[1]) if foo[1] > 23

Assuming the logging level is set to debug, this code would emit something like:

.../some_file.rb:123:in `some_method':
d| foo.size=4
d| foo=[ "bar", 42, :baz, T ]

.../some_file.rb:126:in `some_method':
w| foo[1]=42


The Ruby Console is a fine place to display small amounts of text and run one-line commands. However, it has some significant drawbacks as a debugging aid.

  • It is unwieldy for viewing large amounts of log output.
    • It ain't no RubyMine (:-).
    • It ain't even a text editor!

  • It disappears whenever SketchUp isn't the foremost app.

  • It is unwieldy for viewing large amounts of log output.

So, SketchApps can create a log file ($HOME/.sa_log_file) to store all of the PF_Logger output as well as other voluminous traces.

For example, the trace_me method can write lines to this file documenting method entries. The combined output looks something like:

.../pc_misc.rb:278:in `setup':
i| Report Maker
> PC_Schedules.initialize
> PC_Misc_RM.check_file_path

I view the log file via a TextMate (Mac OS X text editor) window. This gives me code folding, scrolling, searching, and other useful features.


In its native form, the WebDialog is rather uncommunicative. It doesn't run in a normal web browser, so it doesn't write to a console log, provide debugging and code inspection tools, etc.


If the WebDialog is initiated by means of set_file, a browser can be used to inspect the initial HTML, CSS, etc. SketchApps provides .../Tmp/dialog as the default location for these files.

However, this isn't very useful for tracking dynamic HTML content. So, I added some code that updates the HTML file along with the DOM, allowing a browser to (refresh and) display the current content.

Firebug Lite

Firebug Lite is a set of Open Source JavaScript code, intended to provide browser-independent debugging support. It appears to work in WebDialogs and seems quite promising.

Here, with thanks to John Shoffner of Igloo Studios, are some usage hints:

Getting Started

Modify the top of the head section of your HTML file:

<head debug="true">
  <script type="text/javascript"
          src="" />

Alternatively, you could download firebug-lite.js and load it from your local machine.



If none of these tools do the trick, you may want to try Browser_Dialog. This hack allows dialogs to be sent to a web browser (eg, Safari), providing:

  • access to the full range of browser-based debugging features

  • support for dynamic interaction (eg, callbacks, JavaScript)

The Browser_Dialog server (currently Mac-only) is based on EventMachine and Ruby. It runs as a user-mode daemon on the local machine, exchanging messages with the plugin (via files) and a normal web browser (via WebSockets).

Once the server is working, all you need to do is tell SketchApps to use it ($HOME/.sa_config).

This wiki page is maintained by Rich Morin, an independent consultant specializing in software design, development, and documentation. Please feel free to email comments, inquiries, suggestions, etc!

Topic revision: r1 - 05 Oct 2011, RichMorin
This site is powered by Foswiki Copyright © by the contributing authors. All material on this wiki is the property of the contributing authors.
Foswiki version v2.1.6, Release Foswiki-2.1.6, Plugin API version 2.4
Ideas, requests, problems regarding CFCL Wiki? Send us email