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

Figure 6.15 shows the result of importing a large file consisting of point coordinates<br />

using the method described here. The raw data in this case came from a LIDAR flyover of a<br />

historic church.<br />

Figure 6.15: Construction points from an imported file<br />

IN-DEPTH<br />

Working <strong>with</strong> Text Files<br />

As the preceding example shows, it is quite easy to work <strong>with</strong> text files. The common<br />

approach to reading from a file is this:<br />

filename = ‘data.txt’<br />

f = File.open(filename)<br />

f.each { |line|<br />

# Do something <strong>with</strong> the line here<br />

}<br />

f.close<br />

Alternatively, you could replace the middle three lines of this code <strong>with</strong> content =<br />

f.readlines, which reads the entire file as an array into the content variable. You would<br />

then use content.each to iterate through the lines.<br />

To write to a file, use this syntax:<br />

filename = ‘data.txt’<br />

f = File.new(filename,’w’)<br />

256

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

Saved successfully!

Ooh no, something went wrong!