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

The attractor can be any object. For convenience, I like using either component instances<br />

(the default figure in <strong>SketchUp</strong>’s template—lately, “Susan”—for example) or groups or construction<br />

points, but it is up to you to decide what works best in your case. Just modify the<br />

code examples slightly to make them work if you deviate from the examples.<br />

Coloring Faces by Proximity<br />

This code takes several faces and one or more component instances and then colors the faces<br />

according to their proximity to the centers of the component instances (the “attractors”). A<br />

face that is close to an attractor gets a blue color, one that is far away turns yellow, and any<br />

faces in between receive colors from a graduated spectrum.<br />

This example uses a facade made up of several 4’ × 8’ glass panels. These are simply<br />

faces (rectangles) copied edge to edge. We leave them all ungrouped so that the code can<br />

identify them as faces. In addition, we place one to three copies of the default <strong>SketchUp</strong><br />

“person” in various locations and <strong>with</strong> differing distances to the facade (the closest is the<br />

one on the left side). Before running the code, select all of the faces and the people components.<br />

Figure 6.22 shows the raw setup <strong>with</strong> the facade panels and only one attractor. It<br />

also illustrates the result of running the code on this setup.<br />

Figure 6.22: Single-attractor-based coloring of facade panels<br />

Paste this code into the Ruby Code Editor, select the necessary objects in your <strong>SketchUp</strong><br />

model, and then click on Run:<br />

# Color faces by proximity to component attractors<br />

sel = Sketchup.active_model.selection<br />

# Array <strong>with</strong> attractor center points<br />

attractors = []<br />

# Adjust this value to play <strong>with</strong> the scaling<br />

max_val = 500<br />

# Get all ComponentInstances as attractor points<br />

sel.each { |e|<br />

267

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

Saved successfully!

Ooh no, something went wrong!