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

}<br />

}<br />

face = ent.add_face [i*s,j*s,0],[i*s,j*s+w,0],[i*s+w,j*s+w,0],<br />

[i*s+w,j*s,0]<br />

# then pushpull it to get a box<br />

height = 100.feet + rand(100).feet<br />

face.pushpull -height<br />

Figure 6.11: A small city <strong>with</strong> buildings of random heights<br />

Figure 6.11 shows how to use dimensions other than inches in a script and how to employ<br />

the built-in random number generator to add variation to your creations. Giving anything<br />

generated by a computer at least some randomness usually adds quite a bit of realism. We<br />

will use this later <strong>with</strong> transformations, as well.<br />

Randomizing Extrusions<br />

Instead of applying randomized extrusions to newly created geometry, this example applies<br />

them to already existing geometry, which allows us to learn about using selections.<br />

First, create some geometry in your model; you need to have several faces at your disposal.<br />

For this example, I used one of <strong>SketchUp</strong>’s preinstalled spheres as well as a square face<br />

<strong>with</strong> intersecting lines (see Figure 6.12). Make sure the front (the white side of each face)<br />

was always pointing outward and upward; use the Reverse Faces right-click tool if you need<br />

to correct any. Then select everything. Paste the following (very short) snippet into the Ruby<br />

Code Editor in <strong>SketchUp</strong> and click on Run Code:<br />

# Randomly extrudes selected faces<br />

sel = Sketchup.active_model.selection<br />

251

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

Saved successfully!

Ooh no, something went wrong!