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 />

As you can see, the Ruby Code Editor has a few advantages over <strong>SketchUp</strong>’s Ruby Console.<br />

For example, you can enter multiline text, source code is highlighted appropriately, and you<br />

have Run and Undo buttons. Furthermore, you can save and open code snippet files and<br />

even work on files in HTML and other languages. There is also a handy drop-down that lets<br />

you insert common code snippets at the current cursor position. For now, we’ll ignore some<br />

of the more advanced features, however. Just peruse the editor and discover some of its<br />

tools on your own terms.<br />

Now you are ready to tackle all of the examples in this chapter.<br />

Other Options: More Plugins and External Editors<br />

There are some alternatives (all free) to my Ruby Code Editor plugin that have more or less<br />

the same functionality. All of them work fine <strong>with</strong> the examples in this book.<br />

NN<br />

NN<br />

WebConsole—This plugin written by Jim Folz was the original multiline editor on which<br />

I based my editor. You can download it from here: http://sketchuptips.blogspot.com/2007/08/<br />

plugin-webconsolerb.html.<br />

Ruby Console Pro—This plugin was written by Martin Rinehart and offers a multiline<br />

editor as well as a script environment, which provides shortcut functions for common<br />

tasks. http://forums.sketchucation.com/viewtopic.php?t=28571.<br />

If you prefer not to use plugins at all, or if you like using an external code editor, then<br />

you can use this method:<br />

1. Using any text (or Ruby code) editor you like, create a text file source.rb (or similar) in<br />

any convenient location, such as in the root of the C-drive.<br />

2. Add some Ruby code to it and save the file.<br />

3. Open the Ruby Console in <strong>SketchUp</strong> and type the following line when you are ready to<br />

run the code: load ‘C:\source.rb’.<br />

4. This loads all code from the file and executes (runs) it line by line.<br />

If you prefer the external-editor method and you become more familiar <strong>with</strong> writing Ruby<br />

code, then it might be a good idea to add the load script to <strong>SketchUp</strong> as a menu item (using<br />

a small plugin that you will have to write). This gives you one-click access to the function.<br />

Another (more advanced) method is to use the free <strong>SketchUp</strong> Bridge tool that you can<br />

download here:<br />

http://plugins.ro/labs/bridge_tut.htm<br />

TIP<br />

Intro to Ruby and the <strong>SketchUp</strong> API<br />

This section gives you a primer for the Ruby language as well as an overview of the most<br />

important aspects of <strong>SketchUp</strong>’s API. If you need more in-depth information, follow any of<br />

the links at the end of the section.<br />

235

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

Saved successfully!

Ooh no, something went wrong!