Monday, February 24, 2014

Make (Polygon) Faces Anywhere and Produce a Sketchup Model

Sketchup Make is a helpful tool from Google that allows you to fairly quickly create a visual of your building project ideas.  The commands are relatively simple, although you can get a great deal of (intentional) variety in your results with practice.  Sketchup (including Sketchup Make) also allows the user to extend the functionality of the program using Ruby scripts (I say scripts because in Sketchup they are not compiled prior to use but either interpreted or compiled/run every use—not sure which).

But if you'd rather not learn Ruby right now or if perhaps programming just isn't your thing, there's a simple tool that can help you turn columns of numbers into a Sketchup model. I've written a text file importer (specifically, *.csv file format) that will interpret each row of numbers as the vertices of a face or of a polyline (depending on the beginning of the line).

The deal is, you need to make a CSV file (Comma Separated Values) which has all of the points you need in it. You can make these in Excel.
Fig. 1. Screen shot of a *.csv file open in Excel. Each group of 3 consecutive numbers is interpreted as a 3D point.
Any number of points is allowed per line, though you'll need them to be co-planar if you want a face.
The next two screen shots show an example of how you can set up a spreadsheet to calculate a segment approximation of a sphere. (Kind of like a segment of an orange.)  Click on them to see them at full size.

Fig. 2. Segment of a sphere calculation
Fig. 3. View of the formulae used. Not very complicated, but very organized.
Note that you will need to have the vertices for a face in either clockwise or counter-clockwise order. Copy the vertices on the right, go to a separate sheet of the workbook, and use the paste values option. Save your spreadsheet and then Save As, select "CSV" and name your file appropriately. (This will make the CSV file you need but if you want to go on making changes to your original spreadsheet, you would be best to reopen that spreadsheet. As per the usual behaviour of Save As, your original spreadsheet prior to Save As is now closed and you only appear to still be in the same spreadsheet. Kind of irritating.)

Fig. 4. Save As dialog in Excel. Select CVS format.
Here is an animation of a model that I started with a CSV file using the paraboloid tab of the pictured spreadsheet. I then did a rotate-copy a few times to get the completed shape.


8 segment approximation to a paraboloid from Darren Irvine on Vimeo.

What Do I Need in the CSV File?

Each line must start with line or face followed by a comma. Commas are what separate the entries. New lines separate each line and face. The lines are treated as polylines.  For a face you will need at least 9 numbers (or 12, 15, 18, etc., numbers) separated by commas after the first item, like so,

     face,0,0,0,10,10  ,11 ,  55,100 ,  44

Extraneous spaces are okay as long as they don't interrupt a number. It's okay if your lines trail off, as in

     face,0,0,0,10,10,11,55,100,44,,,,,

But you don't want blank entries in the middle like

     face,0,0,,0,10,10,11,55,,100,44

or random non-numeric data like this

     face,0,0,don't put this here,0,face (not here, at the beginning!), 2343, random illegᾳλ χaρaχτeρs: θ, 40,44

Faces will only work as intended if you list the points in either clockwise or counter-clockwise order. You'll end up with a tangled mess otherwise. As for polylines (line), the script will just assume you know what you're doing, although you still should give it point information as for faces.

My script shouldn't cause your system to crash if you feed it bad data, but just the same, play it safe and save your Sketchup model prior to running the script. The import does not start a new file on its own, it imports into the current model—which may be empty.

What Tools Do I Need?

  • Sketchup Make (or above): Sketchup Make is free.
  • dsi_csvfaces.rb: you can obtain the ruby here. Copy it into your Plugins directory. In Sketchup 2015 this is C:\Users\<your_windows_user_name>\AppData\Roaming\SketchUp\SketchUp [n]\SketchUp\Plugins (see http://www.sketchup.com/intl/en/developer/docs/loading).
  • An example:  Have a look at my example spreadsheet which contains a way to approximate a segment of a sphere and a paraboloid.
  • A little ingenuity: make the CSV file anyway you know how. Excel is only one option, but I think it's one that many users are likely to be adept at. You may want to use a programming language (perhaps you're a programmer, but not into Ruby or have intellectual investment in some other means). You may want to use a computer algebra system like Maxima (free), Maple V, or Mathematica. Maybe Javascript. All at your option. You just need a CSV file.
Post a Comment