I have a number of 3D lines which I can load from a file and draw in the Sketchup window with a script via the ruby console. I would like to be able to step through the lines one at a time. I suspect it's not available because of the working environment. gets, chomp, STDIN does not work.
Code would look like this:
Until no_more_lines
ent.add_edges line
#wait for key board activity at the console
next # line
Any suggestions appreciated
Stopping script execution
6 posts
• Page 1 of 1
Re: Stopping script executionuse IO::readlines to create an array...
create a method that uses one pair of points and then removes them from the array... call the method... use the UP arrow and return in Ruby Console to call again... rinse and repeat until array is empty... add an example text file for more explicit code... john learn from the mistakes of others, you may not live long enough to make them all yourself...
Re: Stopping script executionHi John,
Thanks for the suggestion. Will see what I can do with it. Everett Re: Stopping script executionHi John,
Got it working. Thanks for pointing me in the right direction. Had to do a bit of learning along the way. I used the CSV and JSON classes. My main script read the original data, processed it into 3d points, and produced an array of lines. After I got all the lines working, I added a block to write the array to file. The second script reads this file, draws a single line, removes it from the array, and writes the array back to file. Here's the pseudo code for the second script: # access the entities container | | # load required classes require "CSV" # take a working copy of the file # check each time through unless File.exist? <filename> #take a copy end # load the lines into an array line_arr = CSV.read(<filename>) # convert points from string to array of floats # this caused the most grief until I got it right line_arr.map! {|line| line.map {|pt| JSON.parse(pt)}} #draw a line ent.add_edges line_arr[0] #dump the line line_arr.shift #replace the array in the file after checking for last line if <last line> File.delete(<filename>) else CSV.open(<filename>,"wb") do |csv| end[/pre] end #use the up arrow to execute as many times as lines Re: Stopping script executionit looks a bit over complicated...
do you really need JSON when you can use CSV with a options hash...
here's a little experiment to step using the mouse wheel... you may need to 'click' to run the gif... change the path to file...
learn from the mistakes of others, you may not live long enough to make them all yourself...
Re: Stopping script executionI did think it was a bit complicated myself. Most of my programming experience was years ago on 3rd GL stuff. All this is new, but I do have fairly good programming sense.I did try the CSV modifier, but I wasn't using it correctly. That's when I stumbled on JSON. It's only a one shot deal for me, but I have to admit, I do like Ruby! Will be studying your example.
Thanks again. Everett
6 posts
• Page 1 of 1
|