Ruby Code Editor
This code editor plugin offers an easy-to-use and visually appealing way to create and modify Ruby scripts directly within SketchUp.
Ruby Code Editor

This code editor plugin offers an easy-to-use and visually appealing way to create 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 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 in a tab. Also, a dropdown above the editor contains some common code snippets that can be inserted at the current cursor position. Version 3.0 also introduces a code-completion feature that you can invoke at any point by clicking CTRL-SHIFT. It contains SketchUp’s classes and methods.

The other reason I wrote this as a plugin that works right inside of SketchUp is that I wanted it to give easy access to the Ruby coding environment and behave a bit more like a real code editor. To accomplish this, I added a bit of jQuery magic to make it look good and have some additional features. I also added the excellent CodeMirror 3.1 syntax highlighting engine. This provides the editor with multi-language code highlighting, correct TAB control, bracket matching and many more features. Just load the plugin and give it a try to see for yourself!

At this point, this editor has the following features:

  • Execute multiline Ruby code directly in SketchUp
  • Open and save files of any size
  • Fast opening of large files
  • Nice and clean user interface
  • Tab key works as expected in editor (inserts spaces or tabs)
  • Indenting/dedenting of code blocks
  • Dropdown with code snippets inserts snippets at cursor
  • Code-completion for SU classes and methods (click CTRL-SPACE to activate)
  • On save, a backup file can be created
  • Text size dropdown selects editor font size
  • Line numbering in editor
  • Matching brackets highlighting
  • Undo in editor
  • Undo (of code execution) button next to run button
  • Single undo for entire code or multiple undo steps
  • Results window keeps track of history
  • Reliable editor dialog resizing
  • Tab and accesskey navigation
  • Reference web browser for common websites
  • Browser zoom (a little buggy!)
  • Style changer for user interface
  • Buttons to explore selection object properties and object attributes
  • Button for direct access to the Ruby console
  • Clean printing of code
  • Version update checking

Credits:

This editor was originally an extension of Jim Foltz’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 Codemirror 3.1 extension. I am also grateful for many comments and suggestions from Dan Rathbun and others at SCF.

Usage:

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

You can also find this plugin on GitHub.

More Info and Help:

http://www.alexschreyer.net/projects/sketchup-ruby-code-editor/

Reviews

Minh N.'s picture

After join Ruby world for a week, I found this wonderful plugin. Thanks, Alex!

Hello,
I just install Editor which worked the first time.
I close and reopen Sketchup 2015, and when I want to launch Ruby editor, nothing occurs, and Ruby console display the following. And I am not a Ruby expert ;)

Error: #
C:/Users/xxx/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/as_rubyeditor/as_rubyeditor.rb:225:in `split'
C:/Users/xxx/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/as_rubyeditor/as_rubyeditor.rb:225:in `initialize'
C:/Users/xxx/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/as_rubyeditor/as_rubyeditor.rb:522:in `new'
C:/Users/xxx/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/as_rubyeditor/as_rubyeditor.rb:522:in `block in '
SketchUp:1:in `call'

Line #225 is : @snip_dir = @snip_dir.split("/").join("\\") + "\\"

Julian S's picture

Hi Alex, I think I found an error in your RCE (3.2), when it is loaded and you go to > Options > Get Updates > Check for updates it returns "You have the latest version (3.1)" which isn't correct as the latest version (which was downloaded moments before and installed) is 3.2.

alexschreyer's picture

Thanks for pointing this out. This particular mechanism has been superseded by the EW update checking, so I will remove it in the (now quite overdue) next version.

Chin Huat T's picture

Hi Alex,

Great editor. I like it. However It is a pain to remember the plugins directory where all ruby scripts are stored.
Appreciate if you can provide an option to "remember" the plugins directory in the options menu.

As an example, my plugins directory is
"C:\Users\ChinHuat\AppData\Roaming\SketchUp\SketchUp 2016\SketchUp\Plugins"
and it is very long and difficult to remember.

Thanks and Regards,
TCH

Thank you Alex for the quick answer
I could not find how to send the screenshot.
The windows lists
<<
•Ruby Code Editor
•Reference Browser
•Options
•About
...
insert at cursor: ruby
...
untitled.rb
...
1
mod = Sketchup.active_model # Open model
2
ent = mod.entities # All entities in model
3
sel = mod.selection # Current selection
running...
Cleared the editor
>>

any idea?

alexschreyer's picture

Looks like the window doesn't show JavaScript. I am guessing you are on Windows.
Try this: Open Internet Explorer on your computer and make sure you are running the latest version (IE 11). Update if necessary. http://windows.microsoft.com/en-us/internet-explorer/which-version-am-i-...

Amira M.'s picture

I'm having the same problem too. The script is not loading when I choose an .rbz file

alexschreyer's picture

Are you trying to load an RBZ file into the editor? That won't work because the RBZ file is a compressed (binary) file. If you want to explore any of the RBZ extensions, rename the RBZ file ending to ZIP and then open it. Take any RB files out of the compressed folder. You can then load them into any editor. It's a great way to learn coding.

Amira M.'s picture

Thank you so much for you prompt reply. I'm all new to this and I want to edit a line in an RBZ file for plugin I've downloaded.
I made the file .zip file (compressed it) but it didn't work, also I tried just renaming the file as .zip and opening it but it didn't open, so I didn't get to take the .rb files out of the folder. sorry this seems dumb.

I have the same problem also. I'm using sketchup 2015

Dear Alex
Sorry, wonderful tool, but I do have a problem installing it:
sketchup2016 and plugin installed from within sketchup/window/preferences.
But not the nice code-highlighted editor appears later (window/ruby code editor) but an ugly whithe window titled "Ruby Code Editor" with "insert at cursor:"/"ruby" in it.
But I cannot see any coding windows.
Can you please help????
Thanks!!!

alexschreyer's picture

That's odd. Any chance you could get me a screenshot? You can upload one on my website in the comments (see link above). It may have to do with your Internet Explorer version. Update it to the latest version.

I don't know how I would have been able to learn Ruby without a decent environ to play in. This app is a must. Thanks!

alexschreyer's picture

Great to hear!

W R's picture
W R

Hi, Alex, thanks for the great editor!
Is there a way to change the key combination for auto-complete? The ctrl+space conflicts with the input method on windows machine, would like to find a easy way to change the shortcut key if possible.

alexschreyer's picture

Good idea. I logged it as a feature request for my next iteration.

mark p's picture

this is a must have for anyone starting to model with Sketchup. Nothing like having ruby right at your fingertips. I especially recommend this for schools so kids can see that coding, visualizing, and designing all work together.

Bryan B's picture

Worked great the first time I used it . Will not appear again. It is listed in Windows and the tool bar is there but no editor.

alexschreyer's picture

I haven't heard of that before. Do you have any other editors installed? What happens if you uninstall and reinstall the RCE? Still the same?

3skeng©'s picture

Great Plugin, very helpful. Thank you, Sebastian

Abubakar I.'s picture

I install it the way you wrote, but it haven't work.

Pattilyn C's picture

Successfully installed!

I was experiencing invisible folders due to Maverick operating system.

Looking forward to learning how to use Ruby Editor now!

Pattilyn C's picture

I'm sorry this is a dumb question but I'm really struggling to install the Plugin. I'm using a Mac but also a student version of Sketchup 2014 so just wondering if there are restrictions based on this version that are preventing me from installing?

I have followed your instructions but no luck.

Any help most appreciated.

WOFF3D's picture

I just started to work with it. Some small questions. 1) Is it possible to keep RCE on top of SketchUp. Everytime I click on SketchUp window I have to find RCE underneath. 2) When I use puts I don't see the output in the results window. Am I doing something wrong.
Thanks for your great work.

Krgds Charles

so beautiful! thx!

Tyrone M's picture

Very nice plugin, please consider adding find or search function.

Consider for MAC OSX users the addition of the following to keep toolbar from always loading up at startup:

instead of this code
--------------------------
as_rce_tb.show

use this code
--------------------------
 state = as_rce_tb.get_last_state
 if(state==TB_VISIBLE)
   as_rce_tb.restore

Scott Lininger's picture

What a fantastic plugin! Highly recommended for any SketchUp Ruby Developer. It is also very nicely structured, so if you'd like to see a good way to subclass SketchUp's WebDialog, take a peek at the source code. Thanks, Alex!

alexschreyer's picture

Thanks, Scott! Very glad you like it.

6536 users
Size:
412.98 KB
Version:
Ruby Code Editor (3.2); April 25, 2013
Number of Views: 
61692
OS Compatibility: 
Languages: 
Popularity: 
Extensions: 7
I am a Senior Lecturer at the University of Massachusetts and author of the book "Architectural Design with SketchUp". My favorite topics are SketchUp, AEC-CAD/BIM, Wood Engineering, Web Design, and Photography.