Turn 3D model dimensions into a text file?
-
IIRC there is someone here on the SCF working on a project whereby there is an exchange of information between SketchUp and Excel (probably a CSV file generated).
-
An option may be to export to dxf and parse the object text data from there.
It will however require you to write a dxf parser if you can't use any commercial dxf object reader in your project. Not too difficult to do once you understand the dxf file structure. -
Metterz,
As toxicvoxel suggests, I commonly use DXF to both import and export a text file describing lines, endpoints and faces. Note that most DXF files are text files. (Some can be binary, but SketchUp will export the ASCII text version.)
You can use a text editor, if the model is not too complex, but I also (more often) use Excel. You can learn about the DXF format at the AutoDesk website:
Regards,
Taff -
I am a total non programmer but the collada (*.dae) file SU is capable to export is also a text file (in *.xml format).
XML format is becoming kind of "popular" nowadays, too. The advantage of it is that even the free version of SU exports it - hidden in the kmz file which is actually a zip file (you can rename it and open it to see within the model folder).
-
Do you mean simple width, depth, and height information? If so, then you could use Groups to specify each "thing" and export its overall dimensions to a text file.
-
Ok there's no way I can afford SU Pro to export anything other than .kmz files. Is it possible to make a text file without exporting files, eg. using Ruby?
-
And besides, the program's meant to be written for an end user, so the SU part of the whole thing has to be the freeware version...
Thanks all for your help
-
@metterz said:
Ok there's no way I can afford SU Pro to export anything other than .kmz files. Is it possible to make a text file without exporting files, eg. using Ruby?
Yes, it's possible, but it's not clear to me exactly what data you need as the output?
-
Just a string of numbers will probably do, like maybe co-ords of each corner of each group/component. I just need some text file data that MS Access can use to easily acquire the dimensions of groups/components in a SU file. It will probably easier if I can make an Excel spreadsheet though, instead of a text file.
I don't know how the contents of the dimensions file will be arranged, but i'll try to work with whatever I can get out of the SU model -
At a basic level, this will do what you need.
outfile = File.new( "c;\\output.csv", "w") Sketchup.active_model.entities.each do |e| next unless e.is_a? Sketchup;;Group or e.is_a? Sketchup;;ConponentInstance bbox = e.bounds 0.upto(7) do |i| c = bbox.corner(i) outfile.print "#{c.x.to_f},#{c.y.to_f},#{c.z.to_f}\n" end outfile.puts "\n" end outfile.close
-
Ok thanks a lot, but what language is this code in? I tried entering it into Ruby but it died on the second line... Sorry if i'm being awkward, my programming experience is limited - particularly with SU.
-
I'll be more specific there: it gave me a syntax error message on the second line...
-
Sorry about that, I had to hurry off thismorning.
The following snippet is still not a full-featured plugin. Everything is hard-coded in the script. You will need to edit the script and restart SketchUp to make any edits effective. It is just a quick example of how to do it.
I gave it a menu item in the Plugins menu called "Export corners."
UI.menu("Plugins").add_item("Export Corners") do outfile = File.new( "c;\\output.csv", "w") Sketchup.active_model.entities.each do |e| next unless e.is_a? Sketchup;;Group or e.is_a? Sketchup;;ComponentInstance bbox = e.bounds 0.upto(7) do |i| c = bbox.corner(i) outfile.print "#{c.x.to_f},#{c.y.to_f},#{c.z.to_f}\n" end outfile.puts "\n" end outfile.close end
-
Ok, after entering the first line into the Ruby Console, I got this...
UI.menu("Plugins").add_item("Export Corners") do Error; #<SyntaxError; (eval);149; compile error (eval);149; syntax error UI.menu("Plugins").add_item("Export Corners") do ^> (eval);149
I'm guessing the code isn't intended for Ruby, so where do I enter it to get the plugin working?
-
Oh sorry again - I keep making assumptions that people can read my mind.
Here is a file to download and put in your Plugins folder; then restart SketchUp.
Advertisement