Simple script to update files not quite working.... (novice coder!)

I have a large number of component files (a 2D-faceme plant library). They were purchased years ago and are mostly in SU v.6 format. I want to update them to the current sketchup model, so that their embedded thumbnails update to the larger size of the more recent file format. This ‘quick and dirty’ code is working, but frustratingly, the new thumbnails appear to be showing a side view of the 2D component - so just vertical line appears.
Here is the code:

#  Ruby script to batch update SketchUp files to the current version
require 'sketchup'

def update_sketchup_files(folder_path)
  Dir.glob(File.join(folder_path, '*.skp')).each do |skp_file|
    model = Sketchup.open_file(skp_file)
    model = Sketchup.active_model
# lines below were attempt get front view - did not change thubmail
    view = model.active_view
   new_view = view.zoom_extents 

    status =

# Specify the folder path where your SketchUp files are located
folder_path = 'C:/Test'

Image below shows the files in explorer, large thumbnails are the updated versions of the files which previously looked like the last two shown.

Any ideas how to get the correct front view saved in the thumbnail would be very welcome! I would also like to set the file to ‘Always face camera’ when loaded as a component.

Thanks in advance.

This method does not return a model object.

Sketchup.send_action is asynchronous. It is really only meant for toolbar buttons that the user clicks. So often using send actions, the following Ruby statements can get executed before the action takes place.

That said, if you use Sketchup.send_action("View_Front:") at the console, you’ll likely get false returned meaning that the argument was invalid.

The actual send action string argument is "viewFront:" not "View_Front:". Pay a bit more attention to the API documentation perhaps.

You probably also need to do the zoom extents after setting the camera to the front view.

1 Like

Hi - thanks for the reply. I had actually just discovered myself that the underscore in View_Front was wrong, not sure if I copied that from somewhere or mistakenly added it myself.
So with that corrected, the line returns ‘True’ when entered at the console. Reordering the lines seems to have it working, so thank you for pointing me in the right direction.

1 Like