Get Sketchup::View instance from a specific page with ruby

Assume that I draw a point on the model.active_view, and create another 2 scenes by using different camera settings. I want to get the position of the point by using screen_coords method for each page.

What I current can do is this:

mod.pages.each do |page|
  mod.pages.selected_page = page
  view = mod.active_model

But it has some side effects when using mod.pages.selected_page = page, switch from one page to another will cost some time. After the script was executed, the camera of each page was different from the original one, and it will recover after some seconds.

So is there any way could get the screen coordinates of the point of each page without using mod.pages.selected_page = page method?

There is only 1 instance of the Sketchup::View class for a model.
Pages do not have their own instance.

Page transitions should be switched off whilst you iterate the pages …

mod = Sketchup.active_model
opts = mod.options['PageOptions']

# Get the previous setting:
prev = opts['ShowTransition']
# Set page transitions off:
opts['ShowTransition']= false

pages = mod.pages
view = mod.active_view

# Save the current scene page:
current_page = pages.selected_page

# Map each scene page to a screen point:
screen_points = do |page|
  pages.selected_page = page

# Restore the previous page and transition setting:
pages.selected_page= current_page
opts['ShowTransition']= prev

puts screen_points.inspect

Thanks so much, I got tracked by this problem for a long time :slight_smile:

I forgot to show that the initial page should be restored after the iteration and before restoring the prev transition setting.

Added to above snippet …

pages.selected_page= current_page