Get the correct environment parameters for the scene(aka. page)

I created two scenes, one environment. Both scenes use the same environment, but with different parameters such as rotation. In this case, I can only get the environment parameters of the currently active scene correctly. How do I get the correct environment parameters for an inactive scene?

I use code like this to get the params.

Sketchup.active_model.pages[0].environment.rotation

It looks strange for me, If an Environment object has different parameters, it is another object not the same.

I haven’t dealt with the environment yet, but the “usual” method for page was to temporarily make it current, query it, and restore original state of pages. (However, nowadays they also include scene changes in the undo stack, so take that into account.)

Draft code:

# parameter: Sketchup::Page object 
def get_env_rotation( page )
  model = page.model
  pages = model.pages
  
  #store the current page and switch off page transisstion
  showTransition = model.options["PageOptions"]["ShowTransition"]
  model.options["PageOptions"]["ShowTransition"] = false
  sel_page_name = pages.selected_page.name
  
  # switch to the page in question
  pages.selected_page = page
    
    # quiery what you want, e.g.:
    env_rot = page.environment.rotation
    
  # switch back to original page and restore page transisstion
  pages.selected_page = pages[sel_page_name]
  model.options["PageOptions"]["ShowTransition"] = showTransition

  #return the queried prop
  env_rot
end

Thanks for the reply.

It do works with the draft code. But it’s still weird that environment params may change with the page. The params must be stored somewhere associated with the page, but I can’t find it anywhere.

Is there a way not have to change the current page?

In short, I don’t think so.

I did a test. I created two scenes. I assigned “Construction Zone 2K IBL” to both.

Sketchup.active_model.environments.size => 1

I changed the rotation on each page (12, and 110 but the value doesn’t matter), and updated that pages.

Sketchup.active_model.environments.size => 1

So there is still only one Environment in the model.

As you pointed out, I can only query the rotations belonging to the page when they are currently visible. That is, these values ​​are somehow stored in the pages (maybe there is an Environmentstyles, or something) , and the page change initiate to overwrite the same Environment parameter when switching. There is really no information about this and it is not exposed to API. (I did not find, atleest).

Conclusion. Use my hack above :slight_smile: , or wait till someone smarter than me advice else.

Perhaps, report it here: https://github.com/SketchUp/api-issue-tracker/issues

1 Like

The same thing happens with styles. Basically there is only one model viewport. Each scene uses this one viewport when it becomes active, changing the rendering according to it’s stored parameters and the storage flags.

See:

The same is true for the other parameter types. In order to see what is stored, the page must be active. At some time, you’ll need to see or set what style or rendering options are for a page, and you’ll run into the same rigmarole.

1 Like