Is there another way to get thumbnails for the selected components

I used this method:

model = Sketchup.active_model
selection = model.selection()
model.active_entities.add_group(selection).definition.save_thumbnail(filename)

This method is too slow,I want a faster way

I don’t think, if there is other method at all.
:thinking: However you may try to check the different supported file formats (bmp, jpg, png, tif, pct, and gif) if one of it is faster or not…

What are these thumbnails being used for?

These thumbnails are for display,the waiting time is a little long

Thank you for your attention. I’ll try it

Don’t do that rigmarole. To save out a thumbnail of the model try …

model = Sketchup.active_model
filepath = File.join(ENV['HOME'],'testthumbnail1.jpg')
status = model.save_thumbnail(filepath)

See:

If the model is already saved to storage, then you might also use the Sketchup::save_thumbnail module function.

However both methods just reads the internal thumbnail image as it was last saved.


If you want to save a thumbnail of the current active view, irrespective of what was last saved, then use Sketchup::View#write_image with 256 pixel arguments for the width and height.

model = Sketchup.active_model
filepath = File.join(ENV['HOME'],'testthumbnail2.jpg')
model.active_view.write_image(filepath, 256, 256)

I’m sorry, I didn’t make this clear.I want to get thumbnails of the selected model in the Su viewport.

Thank you for your answer. I tried your method, but it was not what I wanted.

SketchUp doesn’t have a concept of thumbnails for a selection. Only models and components.

What you are doing, or what Dan suggests with writing out an image of the whole view is the closest you get.

1 Like

I want to get the thumbnail of the selected component in the Su viewport (preferably changing with the viewing angle).
I used this

model = Sketchup.active_model
model.definitions[0].save_thumbnail(filePath)

and it’s getting faster.But thumbnails don’t change with the angle of view.The original method is OK.

That sounds like this issue: ComponentDefinition#save_as and #save_copy always generate thumbnail from same angle · Issue #765 · SketchUp/api-issue-tracker · GitHub

Thank you for your answer. I’ll go and have a look