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

Paste the following code into the Ruby Code Editor in <strong>SketchUp</strong> and click on Run Code:<br />

# Creates a square panel <strong>with</strong> a sinusoidal hole pattern<br />

ent = Sketchup.active_model.entities<br />

width = 36<br />

n = 10<br />

s = width/(n+1).to_f<br />

# add the square<br />

ent.add_face [0,0,0],[width,0,0],[width,width,0],[0,width,0]<br />

(0..n-1).each { |i|<br />

(0..n-1).each { |j|<br />

# add the circles<br />

ent.add_circle [s+i*s,s+j*s,0], [0,0,1],<br />

sin(i/(n-1).to_f*PI)*s/5.0+sin(j/(n-1).to_f*PI)*s/5.0<br />

}<br />

}<br />

After running the script, what you see on the x-y plane should look like Figure 6.13.<br />

Figure 6.13: Panel layout <strong>with</strong> sinusoidal pattern<br />

253

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

Saved successfully!

Ooh no, something went wrong!