• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Turn 3D model dimensions into a text file?

Scheduled Pinned Locked Moved SketchUp Discussions
sketchup
16 Posts 6 Posters 2.5k Views 6 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    Metterz
    last edited by 27 Aug 2008, 14:30

    I'm doing a program for computing at college, and I need to input dimensions of 3D objects. It'd be great if I could make models of objects in Sketchup then have it generate a simple text file from which another program could read dimensions, for eventual use in visual basic for MS Access. For now, none of the objects will have any curved edges.
    The text file will have to include dimensions of all the 3D objects drawn in a Sketchup file, preferably with some sort of reference number or name for each object.
    I have no coding experience with Sketchup, so any ideas, code or solutions will be greatly appreciated.

    Thanks!

    1 Reply Last reply Reply Quote 0
    • J Offline
      juju
      last edited by 27 Aug 2008, 20:16

      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).

      Save the Earth, it's the only planet with chocolate.

      1 Reply Last reply Reply Quote 0
      • T Offline
        toxicvoxel
        last edited by 27 Aug 2008, 20:54

        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.

        1 Reply Last reply Reply Quote 0
        • T Offline
          TaffGoch
          last edited by 27 Aug 2008, 21:24

          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:

          ASCII DXF File Format

          Regards,
          Taff

          "Information is not knowledge." -- Albert Einstein

          1 Reply Last reply Reply Quote 0
          • G Offline
            Gaieus
            last edited by 29 Aug 2008, 11:07

            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).

            Gai...

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jim
              last edited by 29 Aug 2008, 11:17

              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.

              Hi

              1 Reply Last reply Reply Quote 0
              • M Offline
                Metterz
                last edited by 31 Aug 2008, 11:16

                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?

                1 Reply Last reply Reply Quote 0
                • M Offline
                  Metterz
                  last edited by 31 Aug 2008, 11:19

                  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

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    Jim
                    last edited by 31 Aug 2008, 12:42

                    @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?

                    Hi

                    1 Reply Last reply Reply Quote 0
                    • M Offline
                      Metterz
                      last edited by 2 Sept 2008, 17:21

                      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

                      1 Reply Last reply Reply Quote 0
                      • J Offline
                        Jim
                        last edited by 4 Sept 2008, 01:23

                        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
                        
                        

                        Hi

                        1 Reply Last reply Reply Quote 0
                        • M Offline
                          Metterz
                          last edited by 4 Sept 2008, 15:24

                          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.

                          1 Reply Last reply Reply Quote 0
                          • M Offline
                            Metterz
                            last edited by 4 Sept 2008, 15:27

                            I'll be more specific there: it gave me a syntax error message on the second line...

                            1 Reply Last reply Reply Quote 0
                            • J Offline
                              Jim
                              last edited by 4 Sept 2008, 20:43

                              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
                              
                              
                              

                              Hi

                              1 Reply Last reply Reply Quote 0
                              • M Offline
                                Metterz
                                last edited by 5 Sept 2008, 10:42

                                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?

                                1 Reply Last reply Reply Quote 0
                                • J Offline
                                  Jim
                                  last edited by 5 Sept 2008, 19:48

                                  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.


                                  export_corners.rb

                                  Hi

                                  1 Reply Last reply Reply Quote 0
                                  • 1 / 1
                                  1 / 1
                                  • First post
                                    16/16
                                    Last post
                                  Buy SketchPlus
                                  Buy SUbD
                                  Buy WrapR
                                  Buy eBook
                                  Buy Modelur
                                  Buy Vertex Tools
                                  Buy SketchCuisine
                                  Buy FormFonts

                                  Advertisement