SketchUp script clips #1: Setup and basic ideas

In this series of posts, I will be exploring how one can create scripted geometry in SketchUp. Traditionally, this has been more the realm of programs like Rhino. And justifiably so. Rhino is NURBS-based and can create and modify curved geometry much better than SketchUp. However, SketchUp is an easy-to-use program for working with polygon-mesh-based geometry. It also has a built-in scripting language (Ruby) and best of all – it’s free. So if you want to script SketchUp to automate small tasks or to create interesting geometry, then this may be a good series of posts to follow.

A word of warning: I will not talk about plugin development for SketchUp – although this may be the logical next step after starting to writing scripts for the program. This is discussed in more detail in the appropriate forums (SketchUcation‘s or Google‘s). I will also not go over basic principles of the Ruby language. That is covered well elsewhere, too. By the way: A great reference is O’Reilly’s $10 reference book on Ruby. And for navigating the SketchUp API, there is of course my SketchUp Ruby Cheatsheet.

The order of these posts is mainly dependent on how I am using the software at the moment. Nevertheless, I will keep the examples as generic as possible so that you can modify them easily to suit your case.

Okay, time to get this started. To begin, download SketchUp if you haven’t done so. This will work fine with the free version but you may want to consider the Pro version if you want to add the capability to print plans or load DWG/DXF geometry. Then install my Ruby Code Editor. Follow the instructions on the website, then re-start SketchUp and the editor menu item will appear under the plugins menu. Here are the links:

You can then try out the editor by loading the “create tubes.rb” file from the snippets folder. This is a textfile with Ruby code instructions. You can execute the code by clicking on the “Run Code” button. Tada! The following image shows what you should see in your model:

Afterwards, click on the “Undo” button to see how you can undo the entire code execution.

Now we’re good to go. Before I post the next clip, play around with the editor and explore its functionality a bit.

By the way: This series will use the SketchUp Ruby API methods that are built into SketchUp. There are plugin developments underway that may simplify some of the tasks and make Ruby scripting simpler. One of these is the alternate API (“Sketch Talk”) that is discussed on this website.

For your reference, these are some webpages that may help you along the way:

Next in this series: Creating geometry