Write Thumbnail image from SketchUp using Ruby

ruby
thumbnails

#1

Hi All,

Anyone, please help for export thumbnail image png format from .skp file format. From the file, I want individual png image. I am really so confused. if anyone was known please let me know. For reference, I attached the image

.skp file

I want to like this for each module
png_file

Thanks,
Siva S


Generate Report -> Thumbnail Image?
#2

Look at View#write_image which corresponds to “Export as Image”.

But you need to zoom the box into the view if you don’t want the full scene to show. You can also hide the other entities, or move the currently exported entity to a temporary layer and make it the only visible layer. You can either change the background color in model.rendering_options and hide axes or use png export and use the transparent argument.


#3


Exports a component-defintion’s thumbnail to a given file.
So you could iterate a selection and extract all of the associated definitions, then save each’s thumbnail to a selected / new folder, naming the thumbnail after the definition ?
The image file-types can be, bmp, jpg, png, tif, pct, and gif…


#4

Something like this: ( select all components and copy paste this in the ruby console, hit enter )

mod = Sketchup.active_model # Open model
sel = mod.selection # Current selection
path = mod.path #current path
mypath= File.join(File.dirname(path),'/') #not the model name

sel.each do |sel|          # you would have to select all components in the model
  compname = sel.definition.name # each component's definition name 
  thumbnailname =  mypath + compname + '.png' # as png
  sel.definition.save_thumbnail thumbnailname
end

#5

Thank you so much @MikeWayzovski. It’s working fine. :slight_smile:

And one more question, From the first image, If I select a single component now, I want to hide all unselected components. Is it possible in SketchUp Ruby?

Thanks,
Siva S


#6
mod = Sketchup.active_model # Open model
sel = mod.selection # Current selection
sela = sel.to_a # Selection as an array
ents = mod.active_entities # Current active entities
enta = ents.to_a # Array of ents
# Iterate ents array
enta.each{|e|
  next if sela.include?(e) # Skip if it's selected
  e.hidden = true # hide it
}
### To UNhide hidden things later...
enta.each{|e|
  e.hidden = false # UNhide it
}

#7

This is my first attempt at ruby anything- I copied and pasted into the ruby console, nothing seemed to happen. Do I go look somewhere for the files or was I to specify the destination somewhere?


#8

Nevermind, looked at my desktop and there they were! Cool!


#9

This messes up when the path has a backslash delimiter (as some OS have). File.join is rather meant to be used this way:

  mypath = File.dirname(path)
  thumbnailname =  File.join(mypath, compname + '.png') # as png

#10

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.