Component Save Thumbnail size?

sketchup

#1

Hi, I am trying to create a preview window in html of a component, now using the save_thumbnail method gives me a 256x256 max output, anyway to change that output to a bigger size?, I know there´s a view.save_image method, but this method relies on what´s already placed in the viewport, i have nothing in the viewport because i am trying to preview a component before placing it…any ideas?


#2

Sketchup::Model#save_thumbnail() writes out the previously saved 256x256 thumbnail image from the current model but does not include any changes to the model since it was last saved.

Sketchup::save_thumbnal() will extract the internal 256x256 thumbnail from the given SKP file on disk.

Ie, meaning that the internal thumbnail images of SKP files are set at 256x256.


This means if you wish larger previews, then you will need to iterate your folder of components, and write out larger preview images ahead of time using Sketchup::View#write_image().

def batch_write_thumbnails
  keys = {
    :width => 640,
    :height => 480,
    :antialias => true,
    :transparent => true
  }
  #
  some_path = UI.select_directory(
    title: "Select Component Directory",
    directory: ENV["HOME"]
  )
  return unless some_path
  #
  Dir::chdir(some_path) {
    comps = Dir["*.skp"]
    comps.each do |skp|
      result = Sketchup.open_file(skp)
      if result
        model = Sketchup.active_model
        keys[:filename]= "#{model.title}.png"
        model.active_view.write_image(keys)
      end
    end
  }
end

#3

Thanks for the reply, yes this is what I´m trying to do right now, save the component, load component, write_image, it will be great to be able to override the 256 limit for an specific component…anyway thanks so much!!