Translate Page

Main Menu

My Related Posts

Links & Ads

[as] Recent Posts

[as] on Twitter

SketchUp Ruby Code Editor

Description

This code editor offers an easy 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 a complete 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.

The other reason is that I wanted it to behave a bit more like a real code editor, so I added a bit of jQuery magic to make it look good and have some additional features. I also added the excellent CodeMirror 2.0 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!

This editor was originally an extension of Jim Folz’s Web Console plugin.

At this point, this editor has the following features:

  • Execute multiline Ruby code directly in SketchUp
  • Open and save files
  • Fast opening of large files
  • Nice and clean user interface
  • Tab key works as expected in editor (inserts spaces or tabs)
  • Indenting of code blocks
  • Dropdown with code snippets inserts snippets at cursor
  • 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 reference websites
  • Browser zoom
  • 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

Downloads

SketchUp Ruby Code Editor v.2.0 (289.82 kB, downloaded 3188 times) - PLEASE NOTE: Download the ZIP file and unzip it into the SketchUp plugin directory (usually at C:\Program Files\Google\SketchUp\Plugins\ in Windows or /Library/Application Support/Google SketchUp/SketchUp/Plugins/ on the mac). Keep the folder structure as it is in the ZIP file. Then re-start SketchUp and look for the new menu item in the Windows menu. If you are updating, just overwrite the old version of this plugin.

SketchUp Ruby Code Editor v.2.0 (RBZ version) (289.82 kB, downloaded 100 times) - PLEASE NOTE: Download the RBZ file. Then open SketchUp (v.8 M2 and above) and go to the Preferences dialog. On the Extensions tab, select "Install Extension..." and browse to the file.

You can also find this project on GitHub.

Screenshots

Main editor window

Browser tab

Win7-style split-view of editor and SU (light UI)

Options page (dark UI)

Credits

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 2.0 extension. I am also grateful for many comments and suggestions from Dan Rathbun and others at SCF.

Lingering problems:

  • Minor issues on the Mac: results don’t output correctly, initial code is not shown
  • Page zoom does not work well in reference browser – just use this as a backup if the font is unreadable
  • Doesn’t like to work when other code editors are running in SketchUp – Just restart SketchUp if there are problems
  • Coloring sometimes needs text change to update

Revision History

  • 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

Next steps

  • http://alexschreyer.net Alexander Schreyer

    Just added the RBZ version of this plugin. If you have SU v.8 M2 installed, give it a try!

    • Gjxiaolong88

      I translated a Chinese version, more offensive, thank you!

  • Newbie

    I just downloaded Sketchup8 and your ruby editor. I am running OS/X 10.6.8. Your editor comes up and all seems to be fine until I hit the “play button”. It then responds with “Running the code…Done. Feedback from Ruby: ” but nothing else (not even a newline) and the code does not seem to run. I typed the example code in from your screenshot above, I have even tried just typing in ‘puts “hi”‘. Same result. As if it never actually sends the code to Sketchup. Did I need to install something else as well? The built-in ruby console works, even when invoked from your editor.

    • Newbie

      Ok, I need to retract that comment. I tried again and loaded your sample scripts and they worked in Sketchup. I must be misunderstanding the point of the bottom section of the editor window. I thought it was like a console, so you could print things out, but all it does is give the “running” messages. Is this working as intended? Is there a way for me to get the output of “print” statements?

      • http://alexschreyer.net Alexander Schreyer

        Yes, this is expected behavior. The Ruby output would show up in SketchUp’s Ruby Console. Just open both the editor and the console and you’ll see.

  • tahw nikcufos

    Nice Tool – I frequently use it to test snippets, during PlugIn development. It does have a couple of minor quirks though. During text insertion/selection/editing – its seems to have problems maintaining focus as a text editor, and frequently behaves as a web browser would – i.e. context menus, keyboard shortcuts – I have to be careful where I place my mouse, to successfully cut/copy/paste text, or even get text to highlight. More often than not, the context menu that pops up, is the one for the browser, not the code editor.

    • http://alexschreyer.net Alexander Schreyer

      I know. That’s one issue I have noticed, too. It’s just not as responsive as a native app would be (because it’s all JavaScript and it runs in IE). I wish Google could add Chrome to both the Windows and the Mac versions of SketchUp. This would make development much easier and would allow for better JavaScript rendering.
      In any case, I’ll see at some point soon whether there’s an update to the code editor available that might fix some issues.

      • http://twitter.com/3dpt Peter Saal

        Maybe you can embed a Chrome Frame?
        http://code.google.com/chrome/chromeframe/

        • http://alexschreyer.net Alexander Schreyer

          I already brought this up with Google and they told me that they need the native browsers (IE and Safari) so that the JavaScript callbacks work properly in web dialogs. I still hope they can figure out embedding chrome.

  • http://alexschreyer.net Alexander Schreyer

    I just updated the Ruby Code Editor to version 2.0. It now features reliable code highlighting. As always, mention bugs here.

  • Macgile

    Hi Alexander :)
    I use a lot ruby Code Editor for my developments.
    It’s really a very good plugin.

    However I encounter a bug.
    When I want commented on a line with the shortcut (AltGr +#) a inputbox opens but not on the good line.

    Best regard

    • Macgile

      sorry I have not seen that there was a post on the same subject. :(

      • http://alexschreyer.net Alexander Schreyer

        I know. I’ll have to take that out of the plugin. Will do that soon.

        • http://alexschreyer.net Alexander Schreyer

          Try the new version now. It’s fixed…

  • Sérgio Bizello

    First, the ruby Code Editor for Sketchup is great.
    Now, the problem: I wrote a code that is part of a master code and it very well in Ruby Code Editor. But, after I copy and paste it in master code and run in Sketchup, it doesn´t works. I can´t solve this problem. What happens?

    • alexschreyer

      Very strange. Did you save the code and then paste or did you just copy from the editor? If you save, then some special characters don't get saved properly (see about page).
      The only other thing that happens in the editor is that the code gets wrapped in an undo group. But that shouldn't affect what's happening.

      • Sérgio Bizello

        Very strange too. Now it is working. How was solved? I copy the code form Ruby Code Editor and paste into a Web Console. After that copy it from Web console and paste into master rb code. It worked. Strange… but worked and has work. Really I don´t know what is this. Very thanks for your reply Alex. I will report some details this "bug" if I find the reasons. Thank you.

  • pierremail.com

    Bonjour,
    I tested your script as sketchup8 linux / ubuntu / wine.
    sketchup works perfectly, but your script does not work.
    by cons, if I use sketchup with windowsxp under vmware so, your script seems to work.
    Why it does not work under wine? would it be a wine problem?
    Bravo and thank you for your great tool!
    Thank you – Pierre Spanish user

  • Liqun

    It looks like very nice and light, and good for Ruby coding and testing in Sketchup as if it was part of it.

    • Liqun

      Can I run a Ruby within the Editor?

      • Liqun

        I find it!

  • GeniX

    Hi,

    I'm working on a AZERTY keyboard and in order to insert [ , ] , | and # I need acces to the ALT Gr key. Pressing the ALT Gr key in the code editor, results in a "pop-up" input field for some reason, preventing correct input in the editor.

    I'm working on Win 7 64 bit with Google Sketchup 6

    • alexschreyer

      Thanks for letting me know. That was an attempt at a code completion that I apparently hadn't removed. I'll take it out in the next version. In the meantime, look into the ui.js file and remove or comment (or modify) this block:

      // Autocomplete – Show input when CTRL SHIFT combination is pressed

      var isCtrl = false;

      var crPos = 0;

      $(document).keyup(function (e) {

      if(e.which == 17) isCtrl=false;

      }).keydown(function (e) {

      if(e.which == 17) isCtrl=true;

      if(e.which == 18 && isCtrl == true) {

      crPos = $('#console').getSelection().start;

      $('#autoplete').show();

      $('#autoplete_txt').focus();

      return false;

      }

      });

      Cheers, Alex

  • mark

    THis is great!!!! It makes those lookups to the Ruby and API so easy.

  • Rod

    Nice work, thank you, works fine on windows 7 64bit.

    • http://intensedebate.com/people/alexschreyer alexschreyer

      Good to hear!

  • eran

    Good work!
    Thanks for the tool!

  • sw96500

    Great tool !

    Work well in my system: Windows XP, IE7, Sketchup Pro 7.0

  • http://napkinsketchup.blogspot.com/ John

    Great idea!

    To get your sample code to work I had to add "Math." to sin function to prevent the error:
    (eval):9:in ‘initialize’: undefined method ‘sin’ for #<WebConsole:0x6e6d5d8>

    • http://intensedebate.com/people/alexschreyer alexschreyer

      Interesting. It works fine for me. Are you on a Mac?

  • Gerrit Hubers

    Dan, it (whatever you may call it (not a SU-tool though!)) was mentioned to show up in the Tools menu. Thats why my insignificant remark. Of course I found it where it should be. And later I checked the code where it is send to.
    I can't catch up with you guys but at least that I could figure out.
    Cheers.

    • Dan Rathbun

      OK.. gotcha.Sorry.. my bad! (I missed the typo.)

  • Gerrit Hubers

    Alexander,

    Hi, I'm Gerrit Hubers / Wo3Dan on the SU forums. Thanks for making this script/editor. Hopefully it's going to help me in getting to know how to write (simple) ruby scripts for SU. I liked Jim's Web Console for it was integrated in SU's environment. For me that's essential for understanding what happens when, when trying/altering snippets. So I'm really excited about this tool!!!
    One verrrrrrry small remark from a simple futur user. Your tool shows up in the 'Plugins' folder in SU, not in the 'Tools' folder.

    Thanks again,
    Gerrit

    • Gerrit Hubers

      Edit: Your tool shows up in the 'Plugins' menu in SU, not in the 'Tools' menu in SU.

      • http://intensedebate.com/people/alexschreyer alexschreyer

        Oops! Just a typo. Thanks for catching it. Of course the tool appears in the "Plugins" menu.

      • Dan Rathbun

        Because it's not a Tool. (Like a Pencil or Protractor.) It's a Utility (and in the Ruby subcatagory.)