Layout compatible index to current scene

In the Layout API a scene to be exported can be set by:

layout_model.current_scene = scene_idx

I would like to set the currently selected scene in the Sketchup model to be exported. The trouble is that I can find no way of retrieving the scene index. I tried the following method:

def self.get_selected_scene_index()
    	scenes = Sketchup.active_model.pages
    	selected_scene = scenes.selected_page
    	scene_count = scenes.count

    	return -1 if scene_count <= 0
    	(0..scene_count).each { |idx| return idx if scenes[idx] == selected_scene }
    	return -1
end

The trouble seemes to be that this method returns the index for the scene where the index refers to the scenes placement among the scene tabs, while the index needed for the Layout export seems to be the chronological index. For example a “Scene 3” can be the second tab but the third added scene in which case the layout export wants index 2 while the method above returns index 1. Does anyone know how to solve this conundrum?

It seems like the above is not quite true. My current understanding is that the Layout Index is just the Sketchup index + 1, so the problem is solved.

Yup!

# Get scene index
model.pages.to_a.index(scene) + 1
1 Like