How to get list of all scenes and switch to a selected scene?


#1

I am developing an extension where I want to show the list of scenes for the model.
If user selects a scene then write the scene to an image.


#2

These should help:
http://ruby.sketchup.com/Sketchup/Pages.html#each-instance_method
http://ruby.sketchup.com/Sketchup/Pages.html#selected_page=-instance_method
http://ruby.sketchup.com/Sketchup/View.html#write_image-instance_method


#3

Thanks a lot @jiminybillybob. That is what i was looking for.


#4

Barebones example …

model = Sketchup.active_model
pages = model.pages

prompts = [ "Choose scene for export" ]
defaults = [ pages.selected_page.name ]
list =  [ pages.map(&:name).join('|') ]
caption = "Export Scene to Image"

choice = UI.inputbox( prompts, defaults, list, caption )

if choice # false if user cancels
  pages.selected_page= pages[choice]
  pathname = UI.savepanel("Save view as ...", ENV["HOME"], "#{choice}.png")
  if pathname # nil if user cancels
    model.active_view.write_image(
      # Options
      filename: pathname,
      width:  800,
      height: 600,
      antialias:   true,
      compression: 0.9,
      transparent: true
    )
  end # IF pathname
end # IF choice

Homework assignment:

Modify the choice inputbox (or add a second inputbox just before the image write,) to add the user’s desired options for width, height, antialias, etc.


#5

Thank you @DanRathbun.