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

styles, tools, etc., collections). Once we get hold of the entities collection, we can add a<br />

face using the add_face method.<br />

The add_face method, in turn, accepts 3D points as arguments; because this face is a<br />

triangle, we need to supply three points. These points, in turn, are sufficiently defined by<br />

an x,y,z coordinate, which we are supplying as a three-member array ([0,0,0] is the point<br />

definition for the origin, of course). This is a triplet coordinate array, which corresponds to the<br />

location based on the x (red axis), y (green axis), and z (blue axis) coordinates, respectively.<br />

TIP<br />

When you look deeper into Ruby, you will learn that what I call an object is often called<br />

a class. I do this to (hopefully) reduce confusion. Technically, methods and the like are<br />

defined in a class in Ruby, which then is instantiated as an object when you use it.<br />

When you start up the Ruby Code Editor in <strong>SketchUp</strong> (installed using the plugin, as<br />

described earlier in this chapter), you see that a few shortcuts are already preprogrammed:<br />

mod = Sketchup.active_model # Open model<br />

ent = mod.entities # All entities in model<br />

sel = mod.selection # Current selection<br />

This makes it easy to work <strong>with</strong> some of the basic collections. With these three lines at the<br />

beginning of our code, we can now simply add a fourth line to accomplish what we did before:<br />

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

If you have selected any objects in your current model, you could simply access the first<br />

selected object using sel[0], for example, to move or copy it.<br />

Instead of going through the list of available objects and methods, the next sections show<br />

you an overview diagram and explore some of the functionality using code examples. To serve<br />

you as a reference, the complete API object and methods listing is included in Appendix C.<br />

Object Reference Diagram<br />

The makers of <strong>SketchUp</strong> have produced a useful diagram, shown in Figure 6.7, that explains<br />

visually the object (or class) hierarchy. Please note that the following are not included in this<br />

diagram:<br />

Core Ruby Classes: Array, Length, Numeric, String; UI Classes: Command, InputPoint,<br />

PickHelper, Menu, Toolbar, WebDialog; Geom Classes: BoundingBox, LatLong, Point3d,<br />

PolygonMesh, Transformation, Vector3d, Vertex; App Level Classes: Animation, Color,<br />

Extension, Importer, Options Manager, Options Provider, Set, TextureWriter, UVHelper;<br />

Observers: OptionsProviderObserver.<br />

242

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

Saved successfully!

Ooh no, something went wrong!