19.12.2016 Views

Architectural_Design_with_SketchUp

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 6 Creating Geometry Using Ruby Scripting<br />

Groupon, and Hulu are among them) run on code<br />

written in Ruby. Besides, it is a very object-oriented<br />

language that is actually quite easy to learn, as you<br />

will see. (See Figure 6.3.)<br />

<strong>SketchUp</strong> itself provides a large variety of tools<br />

and procedures that are available to the Ruby scripting<br />

language using what is called an application programming<br />

interface (API). This gives you access to tools<br />

such as Move or Copy, as well as the entire collection<br />

of materials in your <strong>SketchUp</strong> model, through<br />

many well-documented functions.<br />

Having said all of this, it is important to note that<br />

any tool or method has its limitations. Consequently,<br />

scripting in <strong>SketchUp</strong> also has limitations. For example,<br />

curved shapes are not implemented as perfect<br />

curves, in <strong>SketchUp</strong>’s tool set nor in the API. Because Figure 6.3: The Ruby language’s website<br />

<strong>SketchUp</strong> is a polygon-based modeling software, it<br />

naturally does not have a way to define perfect curves. As you know, circles are always made<br />

up of several polylines in a <strong>SketchUp</strong> model. While this certainly is a limitation, it is also important<br />

to keep in mind that in real construction, curved shapes may be approximated by planar<br />

elements (e.g., plane glass panes on a curved-looking facade)—often for constructability and<br />

cost reasons. As a result, <strong>SketchUp</strong>’s API does not natively support NURBS (nonuniform rational<br />

B-splines)—at least not <strong>with</strong>out a plugin. This is better implemented in other software<br />

programs (McNeel’s Rhinoceros and Autodesk’s AutoCAD, Revit, and Maya, for example).<br />

Nevertheless, creating scripted geometry is quite possible using the freely available version<br />

of <strong>SketchUp</strong>, which lowers barriers of entry and offers the potential for everyone to dabble<br />

in this exciting field and create advanced geometry.<br />

This chapter approaches <strong>SketchUp</strong> scripting in a pragmatic way. This means that every<br />

step in the process of geometry creation and manipulation does not necessarily have to be<br />

scripted—after all, we are not writing a plugin, and <strong>SketchUp</strong> already has a great set of builtin<br />

modeling tools. We’ll script only what can’t efficiently be modeled by hand, using standard<br />

<strong>SketchUp</strong> modeling tools to start or finish a project.<br />

First, let’s set up your computer so that you can easily script using Ruby.<br />

Setting Up Your Computer<br />

Before we do any modifications to <strong>SketchUp</strong>, let’s use Ruby as<br />

<strong>SketchUp</strong> provides it to get you started quickly. In <strong>SketchUp</strong>,<br />

look for a menu item in the Window menu called Ruby<br />

Console. When you click on it, you should see the dialog<br />

shown here.<br />

This is the built-in interface for the Ruby scripting language.<br />

It works simply by accepting a line of code in the text box at<br />

the bottom. Once you hit Enter, the line is executed, and the<br />

result appears in the field at the top of the box.<br />

231

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!