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

    [code] extract png thumbnail image from .skp file

    Scheduled Pinned Locked Moved Developers' Forum
    19 Posts 9 Posters 5.0k Views 9 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.
    • D Offline
      driven
      last edited by

      hi all

      anyone tried Jim's script using ruby 2 in SU...

      I get encoding errors on my mac...
      Error: invalid Unicode escape: /\xFF\xFE\xFF\x0ES\x00k\x00e\x00t\x00c\x00h\x00U\x00p\x00 \x00M\x00o\x00d\x00e\x00l\x00\xFF\xFE\xFF

      If I can get it to run, I can pipe the output and attach it to the skp files resource fork ...

      I think it would be faster then using Sketchup.save_thumbnail(skp,img) for the same purpose...

      I want to compare them...

      john

      learn from the mistakes of others, you may not live long enough to make them all yourself...

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        Not sure - it still works fine for me.

        Hi

        1 Reply Last reply Reply Quote 0
        • D Offline
          driven
          last edited by

          hi Jim

          to clarify, I'm trying to run it in 'Ruby Console' using the embedded ruby 2...

          and it also fails using Jeff's Terminal.app cmd, but mac also uses ruby 2...

          john

          learn from the mistakes of others, you may not live long enough to make them all yourself...

          1 Reply Last reply Reply Quote 0
          • S Offline
            slbaumgartner
            last edited by

            @driven said:

            hi Jim

            to clarify, I'm trying to run it in 'Ruby Console' using the embedded ruby 2...

            and it also fails using Jeff's Terminal.app cmd, but mac also uses ruby 2...

            john

            John, try putting the magic comment at the head of jim's file:

            coding:ascii-8bit

            At least that worked for me from a Terminal window. And the png I got was much nicer than the ones I remember from SU 8 when I last tried this...

            Steve

            1 Reply Last reply Reply Quote 0
            • D Offline
              driven
              last edited by

              @steve
              that stopped the errors, but still not working here...
              send me your copy...
              john

              learn from the mistakes of others, you may not live long enough to make them all yourself...

              1 Reply Last reply Reply Quote 0
              • S Offline
                slbaumgartner
                last edited by

                @driven said:

                @steve
                that stopped the errors, but still not working here...
                send me your copy...
                john

                sent via PM

                1 Reply Last reply Reply Quote 0
                • D Offline
                  driven
                  last edited by

                  cheers Steve that works if I cd into the folder then run...

                  it returns the exact same png as Sketchup.save_thumbnail [if that's set for png]...

                  pixel dimensions vary wildly from skp to skp...

                  you can influence the size by re-saving the skp in v2015, but the logic is a little obscure...

                  one that was 400x183, I re-saved now comes in at 256x256 but that seems to be the limit...

                  it also cropped the image, so needs zoom extents in a square viewport to see all...

                  the upshot is I can use it for a quick'n'dirty batch mode icon generator, but they're not as good as doing them individually using my add icon plugin...1 = resized + batch icon; 2 = as extracted + batch icon; 3 = using add_icon.rb

                  learn from the mistakes of others, you may not live long enough to make them all yourself...

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    jkoll66
                    last edited by

                    I know this post is like a thousand years old, but I was using the "extract_png.rb" from "Jim". It doesn't seem to work in SU2023. I need this to compile a catalogue of all of my components. Is there an updated version out there somewhere? I really need this. Thanks in advance!


                    Extract.png

                    1 Reply Last reply Reply Quote 0
                    • ntxdaveN Offline
                      ntxdave
                      last edited by

                      Can’t you just export the file as a png?

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

                        The long existing method is
                        https://ruby.sketchup.com/Sketchup.html#save_thumbnail-class_method

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • ntxdaveN Offline
                          ntxdave
                          last edited by

                          Ooops, I thought they wanted to create a set of png images of their components.

                          1 Reply Last reply Reply Quote 0
                          • Dan RathbunD Offline
                            Dan Rathbun
                            last edited by

                            @jkoll66 said:

                            I know this post is like a thousand years old, but I was using the "extract_png.rb" from "Jim". It doesn't seem to work in SU2023. I need this to compile a catalogue of all of my components. Is there an updated version out there somewhere? I really need this. Thanks in advance!

                            If you are doing this from within SketchUp, try something like:

                            
                            # SketchUp 2015 or later.
                            def export_thumbnails(source_path = nil, dest_path = nil)
                              #
                              unless source_path && File.directory?(source_path)
                                models = Sketchup.active_model.path
                                if models.empty?
                                  models = File.join(ENV['HOME'], 'Documents')
                                end
                                #
                                source_path = UI.select_directory(
                                  title; "Select Model Directory",
                                  directory; models
                                )
                                return unless source_path
                              end
                              #
                              unless dest_path && File.directory?(dest_path)
                                images = Sketchup.active_model.path
                                images = source_path if images.empty?
                                #
                                dest_path = UI.select_directory(
                                  title; "Select Image Output Directory",
                                  directory; images
                                )
                                return unless dest_path
                              end
                              #
                              Dir.glob( '*.skp', base; source_path ) do |skp|
                                source_file = File.join(source_path, skp)
                                image_file  = skp.split('.')[0] << '.png'
                                output_file = File.join( dest_path, image_file )
                                Sketchup.save_thumbnail(source_file, output_file)
                              end # Dir loop
                              #
                            end ###
                            
                            

                            I'm not here much anymore.

                            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