sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Retrieve size sketchup file using ruby

    Scheduled Pinned Locked Moved Plugins
    7 Posts 3 Posters 395 Views 3 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.
    • G Offline
      glro
      last edited by

      The idea is to prevent sketchup from crashing when a plugin is called on a model the size of which is too big for the computer capacity

      by showing an error message before the plugin is effectively launched

      i didn't find anything in "model info" SU ruby API concerning the file size

      is there a way using ruby?

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        The File.size( filePath ) returns the specified file's size in bytes.
        So if your code gets the SKP model.path and it's not empty, then you can get the size of that SKP...
        Then do what you want with it...

        model = Sketchup.active_model
        path = model.path
        unless path.empty?
          size = File.size( path )
          UI.messagebox("This SKP is #{size} bytes !")
          ### or whatever...
        end
        

        TIG

        1 Reply Last reply Reply Quote 0
        • G Offline
          glro
          last edited by

          OK

          i didn't find this information in
          http://www.sketchup.com/intl/en/developer/docs/methods.php
          nor
          http://www.sketchup.com/intl/en/developer/docs/classes.php

          Thank you, your code works

          As long as the path doesn't contains "é" or "è", or characters like that

          Using french and meters while programming sketchup, makes it more difficult...

          Impossible to detect problematic characters in a path, since ruby answers "Run aborted (error has occurred)" and stops...

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            The problems with accents in File paths and SketchUp's current Ruby on PCs are well know.
            It is a 'PITA' 😲

            Until a better version of Ruby is used by SketchUp [ 🎉 ] for now you could try encoding the path - but it is an unreliable pain...

            ### get 'path'
            if $KCODE=="UTF8" ### what is yours ?
                begin
                  upath = path.unpack("U*").map{|c| c.chr }.join
                rescue
                  upath = path
                end
              end#if
            end
            ### Then do 'File' operation on the encoded string...
            exist = File.exist?( upath )
            size = File.size( upath )
            ### etc
            
            

            TIG

            1 Reply Last reply Reply Quote 0
            • G Offline
              glro
              last edited by

              Yes, it is UTF8

              For now, i shall use the code like this

              begin
              unless path.empty?
                size = File.size( path )
                UI.messagebox("This SKP is #{size} bytes !")
                ### or whatever...
              end
              rescue
              UI.messagebox "problematic characters in the file path"
              return
              end
              

              thank you

              1 Reply Last reply Reply Quote 0
              • tt_suT Offline
                tt_su
                last edited by

                @glro said:

                i didn't find this information in
                http://www.sketchup.com/intl/en/developer/docs/methods.php
                nor
                http://www.sketchup.com/intl/en/developer/docs/classes.php

                Those docs only cover the SketchUp API, refer to the Ruby docs for core Ruby features: http://www.ruby-doc.org/core-1.8.6/index.html

                1 Reply Last reply Reply Quote 0
                • G Offline
                  glro
                  last edited by

                  @tt_su said:

                  @glro said:

                  i didn't find this information in
                  http://www.sketchup.com/intl/en/developer/docs/methods.php
                  nor
                  http://www.sketchup.com/intl/en/developer/docs/classes.php

                  Those docs only cover the SketchUp API, refer to the Ruby docs for core Ruby features: http://www.ruby-doc.org/core-1.8.6/index.html

                  I am not a professional programmer, and sometimes, i even surprise myself when i get a result from the code i just wrote

                  there is intelligence in the code itself

                  Maybe that's why i enjoy so much writing code

                  Next time i don't find something in SU API, i'll look for it in Ruby doc

                  Thank you

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

                  Advertisement