sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Export images: how to?

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 5 Posters 825 Views 5 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.
    • TIGT Offline
      TIG Moderator
      last edited by

      Here my simple script that extracts all of the model's images' image-files into a special folder [Extracted Images] in the model's folder, or if the model is unsaved in the user's home directory.
      To use type extractimages in the Ruby Console...extractimages.rb

      TIG

      1 Reply Last reply Reply Quote 0
      • Didier BurD Offline
        Didier Bur
        last edited by

        Hi,
        Thank you all for resolving my problem. With a mix of all ideas and code, I'll do it ! 😍

        DB

        1 Reply Last reply Reply Quote 0
        • Didier BurD Offline
          Didier Bur
          last edited by

          Yessssssssss,

          Here is my snippet to export images out of a model, assumed these images are NOT used as textures or materials, and if the original images are NOT present at their respective pathes on the disk:

          def exportEmbeddedImages()
          @model=Sketchup.active_model
          @images={}
          @model.definitions.each { |e| @images[e]=e.name if e.image? }
          #@tw=Sketchup;;TextureWriter.new seems buggy because when write_all is called,
          # got the error "<wrong argument type (expected Sketchup;;TextureWriter)>"
          @tw= Sketchup.create_texture_writer 
          
          	@images.each_key do |idef|
          		# find the corresponding face in each definition of image
          		idef.entities.each { |e| @f=e if e.typename=="Face"}
          		#retrieve texture of face and load it in texturewriter
          		if @f
          			#puts @f,@f.material.texture.filename
          			@tw.load(@f,true)
          		end
          	end
          # set the path as needed
          @tw.write_all("c;\\images",false)
          end
          

          Thank you all for your help !

          DB

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            @unknownuser said:

            
            > #@tw=Sketchup;;TextureWriter.new seems buggy because when write_all is called,
            > # got the error "<wrong argument type (expected Sketchup;;TextureWriter)>"
            > @tw= Sketchup.create_texture_writer
            > 
            

            Sketchup::TextureWriter.new is not even documented. All examples from Google use Sketchup.create_texture_writer

            Sidenote:
            if e.typename=="Face"
            That is slow -because it compares strings.

            if e.is_a?(Sketchup::Face)
            This is much faster.

            Thomas Thomassen β€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

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

              @thomthom said:

              @didier bur said:

              @tw=Sketchup::TextureWriter.new seems buggy because when @tw.write_all is called, got the error
              <wrong argument type (expected Sketchup::TextureWriter)>
              Sketchup::TextureWriter.new is not even documented. All examples from Google use Sketchup.create_texture_writer

              Sorry.. noticed that (it was late, too tired to go looking for the constructor.)
              After fiddling around I think that .new is undefined, and calling it just calls Class.new, and certain things in the instance do not get initialized.

              I'm not here much anymore.

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

                @didier bur said:

                Here is my snippet to export images out of a model ...

                a couple of questions:

                (1) why? @images={} and not @images=[]
                (why use a Hash when an Array should do?)
                You'd also need to change @images.each_key to @images.each

                (2) when you use tw.write_all,

                • how does Sketchup name the files for those images that had no name?* what format does Sketchup write the images in?
                  (the original format or all TIIF?)

                I'm not here much anymore.

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

                  @dan rathbun said:

                  @didier bur said:

                  Here is my snippet to export images out of a model ...

                  a couple of questions:
                  (1) why? @images={} and not @images=[]
                  (why use a Hash when an Array should do?)
                  You'd also need to change @images.each_key to @images.each
                  (2) when you use tw.write_all,

                  • how does Sketchup name the files for those images that had no name?* what format does Sketchup write the images in?
                    (the original format or all TIIF?)

                  I agree that an array [] and .each would be the best solution.

                  The texturewriter names the images from their textures' image-path-name - even if it no longer exists as a file - ALL textures will have an image-path. The tw also adjusts the exported file's name, making spaces into underscores and removing all other punctuation - e.f. C:\images\my+image 123-4.jpg becomes myimage_1234.jpg: should this result in two exported images with the same name the later ones have a numerical suffix added so ../my+image 123-4.jpg and ../my-image 123-4.jpg would export as myimage_1234.jpg and myimage_12341.jpg etc. The exported images take the format of the original, deduced from the name's suffix - jpg/png/tif etc.......

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    @tig said:

                    I agree that an array [] and .each would be the best solution.

                    I assumed it was part of a larger piece of code since it used instance variables.

                    Thomas Thomassen β€” SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

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

                      @didier bur said:

                      @Dan: - I didn't even know that an image could have no name...

                      Well TIG says it always has an image.path
                      .. I was going by what you said in the 1st post. You said your image.path=nil ??

                      @TIG: Great answers! I asked because the API is vague. Your info should go into the API TextureWriter.write_all description, most definately.

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • Didier BurD Offline
                        Didier Bur
                        last edited by

                        @thomthom: correct, I need the names for another purpose, along with the associated definition. (su2pov)

                        @Dan: - I didn't even know that an image could have no name... How can this occur (each image has a path (with a file name at the end) ❓ image.path=nil occured only one time with an old model and I cannot reproduce this, so I think I made an error whan typing code in the console or something like that...
                        - tw exports at the original format.

                        DB

                        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