19.12.2016 Views

Architectural_Design_with_SketchUp

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 6 Creating Geometry Using Ruby Scripting<br />

Once you hit Return, you should see a triangle appear in <strong>SketchUp</strong>’s modeling area (at<br />

the origin, to be exact). It should look like Figure 6.4.<br />

You can even access some of <strong>SketchUp</strong>’s user interface components. Just for fun, let’s<br />

open a file selection dialog. Enter this code:<br />

UI.openpanel ‘Select any file please’<br />

As you can see, this one-liner opens a<br />

dialog, lets you select any file, and returns<br />

its location on your computer (the complete<br />

path) in the results part of the Ruby<br />

Console. Don’t worry—nothing will happen<br />

to the file. All you did was ask yourself<br />

for a filename.<br />

As you can see in these examples, the<br />

Ruby Console is already very powerful.<br />

One thing that it can’t do, though, is execute<br />

multiline scripts. For this, we need to<br />

enhance <strong>SketchUp</strong> <strong>with</strong> a plugin.<br />

Installing the Ruby Code<br />

Editor Plugin<br />

Throughout the rest of this chapter, we<br />

use the free Ruby Code Editor plugin to Figure 6.4: Adding a triangle in <strong>SketchUp</strong> using Ruby code<br />

edit and run Ruby code <strong>with</strong>in <strong>SketchUp</strong>.<br />

While this plugin is a convenient way to accomplish the task, there are also other methods<br />

and plugins that work well—they will be described later.<br />

Here’s what you need to do:<br />

1. Go to my website and download the installer file for the plugin. Download the ZIP or<br />

RBZ-version of the installer file (see Chapter 4 regarding how to install RBZ files). www.<br />

alexschreyer.net/projects/sketchup-ruby-code-editor.<br />

2. If you downloaded the ZIP-file, open the file using your favorite ZIP compression software.<br />

Often, your operating system simply opens the file if you double-click it. If that doesn’t<br />

work, use software such as 7-Zip (download from www.7-zip.org) to unzip it.<br />

3. Paste the contents of the file into <strong>SketchUp</strong>’s Plugins folder on your hard disk. You can find<br />

that folder in the following locations. Important: Retain the file and folder organization<br />

as it was included in your ZIP file. Windows: C:\Program Files\Google\Google <strong>SketchUp</strong><br />

\Plugins\ Mac: /Library/Application Support/Google <strong>SketchUp</strong> /<br />

<strong>SketchUp</strong>/Plugins/.<br />

4. Restart <strong>SketchUp</strong>. You should see the following menu item in the Window<br />

menu (next to the Ruby Console menu item you used earlier). Click on it to<br />

start up the code editor.<br />

233

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

Saved successfully!

Ooh no, something went wrong!