[code] extract png thumbnail image from .skp file

[code] extract png thumbnail image from .skp file

Postby Jim » Mon Jan 04, 2010 5:01 am

This bit of Ruby code extracts the png image from a .skp file and writes it to disk using the same basename as the model file.
0
Hi

Jim 
Global Moderator
 

Re: [code] extract png thumbnail image from .skp file

Postby tbd » Mon Jan 04, 2010 10:03 am

yup, i did something similar in 2005, a viewer for .skp thumbnail inside Total Commander - see my blog post (no source though yet)
0
SketchUp Ruby Consultant | Podium 1.x developer
http://plugins.ro
User avatar
tbd 
 

Re: [code] extract png thumbnail image from .skp file

Postby Dan Rathbun » Mon Jan 04, 2010 11:48 am

_
The following code does the same thing BUT must be run from within Sketchup Ruby.
    ( Jim's code can run in standard Ruby, and does not need Sketchup running.)
Code: Select all
folder = Dir.getwd
# browse for another folder here (opt.)
# see TIG's "import_from_folder" script
Dir.foreach( folder ) do |fn|
  skp = File.join(folder,fn)
  img = ''
  # first 2 entries are dirs '.' and '..'
  if File.ftype( skp )=='file'
    if fn.downcase.include?('.skp')
      # it's a Sketchup model
      img = fn.split('.')[0]+'.png'
      img = File.join( folder, img )
      Sketchup.save_thumbnail(skp,img)
    end # if it's a SKP
  end # if 'file' type
end # Dir loop
EDIT-06JAN2010: added downcase to filename .skp test

FYI: There are three (3) save_thumbnail methods

Sketchup.save_thumbnail which can work on files, other than the one that's loaded.

Model.save_thumbnail which only works for the current model, but has a bug, in that if the model has never been saved, it writes a blank thumbnail image to the %UserProfile% folder instead of the Model folder specified in Preferences>Files>Model folderpath.
[BUG - as of SU ver 7.1.6087]

ComponentDefinition.save_thumbnail

There is also View.write_image which can write a thumbnail of the current view that CAN be different than the thumbnail that was saved within the file.
_
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: [code] extract png thumbnail image from .skp file

    Postby nuagevert » Tue Dec 24, 2013 8:52 am

    Hi,
    i would like to know how to extract with better resolution than a thumbail or how t oextract texture from skp files

    thanks a lot ?

    regards
    Gabriel
    0

    nuagevert 
     

    Re: [code] extract png thumbnail image from .skp file

    Postby slbaumgartner » Tue Dec 24, 2013 3:06 pm

    nuagevert wrote:Hi,
    i would like to know how to extract with better resolution than a thumbail or how t oextract texture from skp files

    thanks a lot ?

    regards
    Gabriel


    SketchUp automatically generates a thumbnail image and saves it inside the skp file. That is what Jim's code extracts. You have no control over the size or quality of this image. In my experience, for a complex model it is almost useless. There just aren't enough pixels in it to avoid total blur of the contents.

    To get an image in which you control the size and quality, you must use one of the techniques Dan describes. As he notes, these are Ruby code that runs within SketchUp - though I suppose you could write code using the C API that would do it.

    Steve
    1

    slbaumgartner 
    PluginStore Author
    PluginStore Author
     

    Re: [code] extract png thumbnail image from .skp file

    Postby Dan Rathbun » Tue Dec 24, 2013 6:46 pm

    @Gabriel... do you REALLY use pre-v6 SketchUp ? Did you download it off the web somewhere ?

    Please go to SketchUp.com and download the latest free version. There are very many bugs in those old version, they should be outlawed! :D
    1
      I'm not here much anymore. But a PM will fire email notifications.
      User avatar
      Dan Rathbun 
      PluginStore Author
      PluginStore Author
       

      Re: [code] extract png thumbnail image from .skp file

      Postby nuagevert » Wed Jan 01, 2014 12:05 pm

      thanks you a lot

      i hadnt understand at the begininng it was extraction of thumbail
      so i understand know why their were so little .

      so i will try download for more recent sketchup version and i will try to find the way to find a ruby code or try to done if is not so complicated

      i will try to extract texture of scene and atribute the name of skp object , cause it was that s i exactly want to do

      thanks again and have nice year !

      Gabriel
      0

      nuagevert 
       

      Re: [code] extract png thumbnail image from .skp file

      Postby driven » Sun Dec 28, 2014 10:58 pm

      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
      0
      learn from the mistakes of others, you may not live long enough to make them all yourself...

      driven 
      PluginStore Author
      PluginStore Author
       

      Re: [code] extract png thumbnail image from .skp file

      Postby Jim » Mon Dec 29, 2014 10:12 pm

      Not sure - it still works fine for me.
      0
      Hi

      Jim 
      Global Moderator
       

      Re: [code] extract png thumbnail image from .skp file

      Postby driven » Mon Dec 29, 2014 10:37 pm

      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
      0
      learn from the mistakes of others, you may not live long enough to make them all yourself...

      driven 
      PluginStore Author
      PluginStore Author
       

      Re: [code] extract png thumbnail image from .skp file

      Postby slbaumgartner » Mon Dec 29, 2014 10:59 pm

      driven wrote: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
      0

      slbaumgartner 
      PluginStore Author
      PluginStore Author
       

      Re: [code] extract png thumbnail image from .skp file

      Postby driven » Mon Dec 29, 2014 11:18 pm

      @steve
      that stopped the errors, but still not working here...
      send me your copy...
      john
      0
      learn from the mistakes of others, you may not live long enough to make them all yourself...

      driven 
      PluginStore Author
      PluginStore Author
       

      Re: [code] extract png thumbnail image from .skp file

      Postby slbaumgartner » Mon Dec 29, 2014 11:36 pm

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


      sent via PM
      0

      slbaumgartner 
      PluginStore Author
      PluginStore Author
       

      Re: [code] extract png thumbnail image from .skp file

      Postby driven » Tue Dec 30, 2014 1:00 am

      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...
      2014-12-30 12.13.33 am.png
      0
      learn from the mistakes of others, you may not live long enough to make them all yourself...

      driven 
      PluginStore Author
      PluginStore Author
       

      SketchUcation One-Liner Adverts

      by Ad Machine » 5 minutes ago



      Ad Machine 
      Robot
       



       

      Return to Developers' Forum

      Who is online

      Users browsing this forum: No registered users and 13 guests

      Visit our sponsors: