Can i draw the whole building structure with code?
-
it seems to me that Sketchup Ruby API don't have the CSV library.
should i just use the File class
or should i add the csv module to it
and how? -
@wdbao said:
it seems to me that Sketchup Ruby API don't have the CSV library.
should i just use the File class
or should i add the csv module to it
and how?I used this to collect data from json files (could be csv text files)...
@dlg.add_action_callback("send") { |d, a| nr = Integer(a) subDir = "nset/" files = ["config","nset","mset","words","numbers"] lines = [] file = File.join(File.dirname(__FILE__), files[nr] + ".json") File.open(file, 'r') do |f1| while line = f1.gets lines.push line end end array = [nr,lines] array = array.join("qq") #p array script = "rubyReceive('#{array}')"; d.execute_script(script)
I don't know what you mean by csv library.
-
i mean CSV library as one of the Ruby Standard Library
http://forums.sketchucation.com/viewtopic.php?f=180&t=29544&start=0&hilit=ruby+library -
@wdbao said:
i mean CSV library as one of the Ruby Standard Library
http://forums.sketchucation.com/viewtopic.php?f=180&t=29544&start=0&hilit=ruby+libraryYou can add the paths to the full Ruby Library directories, and load from there.
See a script I posted here, tweek it to your system, version etc.
(code) Ruby LOAD PATHs script for (Win32)You should try to run the same Lib versions as the interpreter that Sketchup loads.
Are you on a Mac/OSX or PC/Win32 ?? -
To talk more about your CSV File question, I thought TIG posted an example here somewhere on the forums.
It's not that hard.
As each line of the file is read ( f = file.readline ) the var contains a string, so you'd use the String method .split and specify the character to split by.
record = f.split(',')
At that point the var record is an Array of String values.It's up to you if you wish to convert each record to Ruby data, line by line; or just collect an Array of record Arrays, close the file, then do your conversions all at once with a nested loop.
-
@dan rathbun said:
To talk more about your CSV File question, I thought TIG posted an example here somewhere on the forums.
It's not that hard.
As each line of the file is read ( f = file.readline ) the var contains a string, so you'd use the String method .split and specify the character to split by.
record = f.split(',')
At that point the var record is an Array of String values.It's up to you if you wish to convert each record to Ruby data, line by line; or just collect an Array of record Arrays, close the file, then do your conversions all at once with a nested loop.
thanks Dan
it is easy to get the data on csv file this way. or any other files -
@wdbao said:
thanks Dan
it is easy to get the data on csv file this way. or any other filesIs this a question ??
Do you want examples ??
EDIT: Well, I posted 1 example using Ruby's IO class:
[code] reading a CSV file -
thanks again.
it is not a question.
your help is greatly appreciated.
the example code you posted is good for separating the header.
but i want to parse the data into hash.
then i can access the data in a natural way. -
@wdbao said:
but i want to parse the data into hash.
then i can access the data in a natural way.OK posted a second example that outputs record Hashes, same thread.
[code] reading a CSV file -
@dan rathbun said:
@wdbao said:
but i want to parse the data into hash.
then i can access the data in a natural way.OK posted a second example that outputs record Hashes, same thread.
[code] reading a CSV fileDan, you are marvellous! this will do.
-
I see that you are progressing well with the "technology" side of csv data storage but I wonder (because I am interested in alternative methods) how you are coping with the complexity of the information itself.
I have been always wary of csv because I associate it with spreadsheets and though I have tried very hard from the early days of Lotus 123 I have not found a way to use them to "turn" data to cope with its 3D nature.
What I mean by turn is illustrated by the diagram to the left which suggests it is natural to use a cross section to review the number of floors in a building but plan section to review each floor's spaces. I think this is sufficient to demonstrate data is 3d in nature (or perhaps more accurately access to it). The animation I have demonstrated before allows me to cope with it in a 2D UI.
Information that is often presented as schedules - rebar, door, sanitaryware, ironmongery(hardware) and so on - can be dealt with in the same way, but the properties of the real (as opposed to code) objects require a data or backup display so that you can see collections of key/value pairs for editting.
So assuming you agree basically with what I describe, it would be would interesting to see both a UI design and the structure of the csv or hash solution to compare with the UI and Javascript object notation (json) that I currently use.
Cheers!
Advertisement