SketchUp Ruby Code Editor

This code editor extension offers an easy-to-use and visually appealing way to write and modify Ruby scripts directly within SketchUp.

SketchUp Ruby Code Editor

Description

editor-icon-512This code editor extension offers an easy-to-use and visually appealing way to write and modify Ruby scripts directly within SketchUp. These scripts can then be used to create geometry, add functionality or add data within the SketchUp 3D modeling environment. The SketchUp Ruby API provides an extensive set of functions to automatize SketchUp in many ways or create scripted, computational geometry.

I created this editor mainly for two reasons: One is that I wanted a way to edit and run SketchUp Ruby code right inside of SketchUp’s 3D modeling environment. Often this is done in an external editor, but having an internal editor allows for using both scripting and modelling concurrently – depending on your needs. The editor had to provide easy access to the Ruby coding environment and behave more like a real code editor. To accomplish this, I added a bit of jQuery (and jQuery UI) magic to make it look good and have some additional visual features (e.g. the tabs and menus). I also added the excellent CodeMirror syntax highlighting engine. This provides the editor with multi-language code highlighting, correct TAB control, find/replace, bracket matching, code folding, and many other features. Just load the plugin and give it a try to see for yourself how easy it is to use!

The other reason for this extension is that when I write code, I permanently need to look up documentation. To make this easier, I added a bunch of reference webpages to a browser window. Also, a dropdown below the editor contains some common code snippets that can be inserted at the current cursor position. I am also experimenting with a code-completion feature that you can invoke at any point by clicking CTRL-SHIFT. It contains SketchUp’s classes and methods.

By the way: Check out my book, “Architectural Design with SketchUp: 3D Modeling, Extensions, BIM, Rendering, Making, and Scripting.” Chapter 7 provides an overview of Ruby scripting in SketchUp and has many tutorials for things to do with this editor.

The following video gives a brief overview of what this editor can do:

Features

  • Beautiful and clean editor user interface with menu-based UI
  • Light / dark themed editor
  • Allows executing multi-line Ruby code directly in SketchUp
  • Works with files of any size
  • Fast opening and code highlighting of large files
  • Most recently used file list
  • Keyboard shortcut navigation
  • Line numbering in editor
  • Indenting/dedenting of code blocks
  • Matching brackets, current line highlighting
  • Undo/redo in editor
  • Find/replace in editor (text or RegEx)
  • Code folding
  • Insert code snippets at cursor
  • Code-completion for SketchUp classes and methods
  • Automatic backup file creation
  • Various options: font size, tab/space indenting
  • Undo of code execution
  • Single undo option for entire code
  • Results window keeps track of run history
  • Reference web browser for common websites
  • Explore selection object properties and attributes
  • Option for direct access to the Ruby console
  • Option to edit default code snippet
  • Clean printing of code

Usage

Select Window > Ruby Code Editor or open from the Ruby Code Editor toolbar.

Some Tips

  • When code highlighting fails (e.g. only a section of the code is properly colored), then that is usually due to too many operators being located too close to each other for the highlighter to keep them apart. Add spaces to fix this (e.g. at the arrow location shown below).
  • The code completion could be better… Will add that in the next version.

Downloads

You can now find this extension in Trimble’s Extension Warehouse. For an easy install (and update notifications), browse to it from inside SketchUp (2013 or newer) and install it directly.

Alternative Downloads

Linked below are the installation files (RBZ and ZIP formats) for the current and some previous versions of this extension.

To install these files, follow the SketchUp folks’ instructions. You can also find this extension on GitHub.

Screenshots

Editor dialog with File menu (light color style)
Editor dialog with Edit menu (dark color style)
Editor preferences
Editor and reference browser windows

Next Steps

Revision History

  • Version 4.1 (7/18/2017)
    – Resubmission to fix EW signing issue
    – Minor fixes and edits
    – Fixed selection reporting
    – Separated selection menu
    – Created new SVG icons
    – Added definition attribute reporting
    – Added inserting of IDs
    – Added more menu tooltips
  • Version 4.0 (7/10/2017):
    – Code cleanup
    – Updated jQuery, jQueryUI, codemirror
    – Updated styles
    – Updated code snippets
    – New menu and tab UI
    – Ref browser and help windows use HtmlDialog now, also separate windows
    – Fixed loading code
    – Fixed recent file bug. Opens in current folder now
    – Fixed printing
    – Fixed preferences
    – Fixed eval binding to be top level (like the Ruby Console)
    – Made line wrapping default
    – Added preloading of optional $LIBRARY_PATH items from preferences
    – Added MRU file list
    – Added quick save option
    – Added undo/redo
    – Added find/replace
    – Added code folding
    – Added ability to edit default code
    – Added help window (link to website)
    – Improved keyboard shortcuts
    – Improved reference browser, updated links
  • Version 3.2 (4/25/2013):
    – Reorganized files and folders
  • Version 3.1 (3/6/2013)
    – Fixed default file bug
    – Updated jQuery cookie plugin
    – Fixed Tab problem
  • Version 3.0 (3/4/2013)
    – Got rid of settings file
    – Results feedback now wrapped in Paragraph
    – Improved feedback scrolling
    – Some CSS changes, separated CSS by theme
    – Two editor themes now: ambiance and eclipse
    – Updated Codemirror to 3.1
    – Updated jQuery
    – Updated jQuery UI
    – Improved editor stability, smoother scrolling
    – Set IE version number to 9 (allows for more features and better display)
    – Fixed SU class highlighting and added SU method highlighting
    – Added syntax highlighting for SketchUp classes and methods
    – Better editor closing handling
    – Changed some options for newer Codemirror
    – Fixed theme color options
    – Better error display
    – Fixed Mac rendering of results window
    – Fixed Mac default folder issue
  • Version 2.1 (2/26/2013)
    – Uses most recently used directory for file loading and saving
    – Fixed the outdated URLs in the browser
    – Update checking now uses www.sketchupplugins.com
  • Version 2.0 (4/12/2011)
    – Switched editor to use CodeMirror – sooo much better!
    – Added code coloring for several languages (Ruby, HTML, CSS, JavaScript, XML, C/Java)
    – Can handle large files easily
    – Added bracket matching
    – Added coloring changer
    – Disabling run button if code is not Ruby
    – Added some more options
    – Added option to disable single undo
    – Added color coding for SU classes
    – Fixed problem with loading/saving slashes in files
    – Updated jQuery and jQuery UI
    – Results window is now continuous and scrolls
    – Added some more code snippets to dropdown
    – Added toolbar item
    – Moved menu item to “Windows” menu
    – Added settings file for modifications
    – Added code printing
  • Version 1.2 (4/13/2010)
    – Updated jQuery UI to v. 1.8
    – Added object explorer button to show current selection details
    – Added attribute explorer button for selection attributes
    – Added button to show Ruby console
    – Modified code a bit
    – Changed buttons to images for space reasons
    – Fixed keyboard access (Alt+…)
    – Added pages to browser: Edges to Rubies, Ruby core and Google search
    – Added basic update checking
    – Enabled browser buttons again – use at your own risk…
    – Waiting icon shown while code executes
  • Version 1.1.2 (3/8/2010)
    – Removed nav buttons also for IE because they disabled code execution after a while
    – Renamed some code elements
    – Added wrapper module
  • Version 1.1.1 (2/25/2010):
    – Safari-related fixes (cookies, text insert, removed back button)
  • Version 1.1 (2/22/2010)
    – Changed webdialog internal name for compatibility
    – Better looking dropdowns under Windows
    – Fixed save filename preselect problem
    – Better code execution and error catching (thanks to Dan Rathbun)
    – Faster file loading for large files
    – Added cookie-based saving of preferences (expires after 365 days)
    – Added changeable user interface
    – Modified some references
  • Version 1.0 (2/3/2010)
    – First release

Credits

This editor was originally based on Jim Folz’s Web Console plugin.

In addition to Jim’s original code and whatever I added and modified, this editor uses the jQuery and jQuery UI libraries. Syntax highlighting is provided by the excellent Codemirror. I am also grateful for many comments and suggestions from Dan Rathbun and many others at SCF.

Links & Ads: