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.

<strong>Architectural</strong> <strong>Design</strong> <strong>with</strong> <strong>SketchUp</strong><br />

# Define all possible translations<br />

t1 = Geom::Transformation.new([100,0,0])<br />

t2 = Geom::Transformation.translation([100,0,0])<br />

t3 = Geom::Transformation.rotation(center, [1,0,0], 45.degrees)<br />

t4 = Geom::Transformation.scaling(center, 2)<br />

# Choose one of them—for now<br />

t = t2<br />

# Transform one object<br />

ent.transform_entities(t, sel[0])<br />

You can test the main transformations simply by modifying the t = t2 statement. Feel<br />

free to experiment <strong>with</strong> the code a bit to test it out.<br />

If you want to apply more than one transformation, then replace this line <strong>with</strong> something<br />

like t = t2 * t3 * t4 (i.e., multiply the ones you want to apply). This combines t2, t3, and<br />

t4 into a single transformation.<br />

The following examples apply these principles in various ways.<br />

Lots of Boxes Using Components<br />

This is essentially the same example that we did earlier. In <strong>SketchUp</strong>, however, the approach<br />

that takes less computational effort and less space on the hard disk than just creating lots of<br />

geometry is usually to create one geometry item (the box, in this case), convert it to a component,<br />

and then just insert component instances. Instead of saving a whole lot of geometry,<br />

only insertion points are thus being stored. This results in smaller file sizes and models that<br />

handle much better (during zooming, orbiting, etc.).<br />

The following code does this by creating a grouped box, converting it into a component,<br />

and then copying (placing) it multiple times using transformations.<br />

# Creates lots of boxes using components<br />

ent = Sketchup.active_model.entities<br />

s = 100<br />

w = 10<br />

n = 10<br />

group = ent.add_group<br />

face = group.entities.add_face [0,0,0],[w,0,0],[w,w,0],[0,w,0]<br />

face.pushpull -w<br />

comp = group.to_component<br />

260<br />

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

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

(0..n).each { |k|

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

Saved successfully!

Ooh no, something went wrong!