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.

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

Let’s try this out: Enter puts “Hello World!” into the text field and hit the Return key.<br />

The result shown here should appear in the dialog.<br />

Because the puts command simply prints something to the result part of the dialog, all<br />

you get as a result is the “Hello World!” string.<br />

You can even get a little more “programmy” by assigning variables. First, enter a = “Hello<br />

World!”, hit the Return key, and then enter puts a. You will find that you get the same result.<br />

In this case, however, we assigned a text string to a variable first.<br />

Let’s try something a bit more useful—let’s do some calculations. As it turns out, you can<br />

essentially use this dialog as a built-in calculator. Enter 2*16, and you should get a result of<br />

32. You can use any of the common mathematical symbols here such as +, —, /, *, and **<br />

for power (as in 2**4 equals 16) as well as parentheses to structure calculations.<br />

To make things more interesting, let’s try a square root. Enter sqrt(10) and you should<br />

see 3.16227766016838 as the result. Nice, isn’t it?<br />

As you might have guessed, you can use any of the usual mathematical operators and<br />

functions here. This is the complete list of all built-in math functions: acos, erfc, asin, atan,<br />

cosh, sinh, tanh, acosh, asinh, atanh, exp, log, log10, sqrt, atan2, frexp, cos, ldexp, sin,<br />

hypot, tan, erf.<br />

TIP<br />

When using any trigonometric functions such as sin for the Sine of an angle, keep in mind<br />

that the argument must be in radians. You must add .degrees (including the dot) to the<br />

angle to get the correct answer. Example: sin(45.degrees) results in 0.707.<br />

Furthermore, although these functions should work <strong>with</strong>out a problem, their complete<br />

“name” is, for example, Math.sin, where the class name “Math” (in which these functions<br />

are defined) is prepended (<strong>with</strong> a dot as shown). Use this syntax instead if you run<br />

into any problems.<br />

While this is all great, the preceding examples use only the scripting language Ruby itself.<br />

Let’s try an example where we actually get <strong>SketchUp</strong> to do something. Enter the following<br />

line of code into the Ruby Console:<br />

Sketchup.active_model.entities.add_face [0,0,0],[0,10,0],[0,10,10]<br />

232

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

Saved successfully!

Ooh no, something went wrong!