How can update rendering_options of page?

Modify rendering parameters only in the current scene.

It’s invalid.

Sketchup.active_model.rendering_options['DisplaySectionCuts'] = false
Sketchup.active_model.rendering_options['DisplaySectionPlanes'] = false
Sketchup.active_model.pages.selected_page.use_rendering_options= true
Sketchup.active_model.pages.selected_page.use_section_planes= true
Sketchup.active_model.pages.selected_page.update PAGE_USE_ALL

(1) You must navigate to the scene page you wish to change,

(2) then be sure to set the certain Boolean flags true:
page.use_rendering_options= true
or
page.use_section_planes= true
or
page.use_style= my_style_for_this_page

(3) Then update the page.

Basically, you must have a page selected and displayed to change any rendering options or style attributes.

If it is a style attribute you wish to change, and if the page has it’s own style object, then you must also select the page’s style in the Styles collection with styles.selected_style=, and then update the page’s style with styles.update_selected_style.

Keep in mind that many rendering options are really Style attributes and the RenderingOptions interface is just a means to access these style attributes.

1 Like

We unfortunately have no direct API to change many of the scene properties. For now you typically have to update the current view and update the scene.

As Dan says the rendering options aren’t saved directly to the Scene but to the Style. This means you can activate the style, update it and switch back to the previous style without changing the active scene, but it also means changes to that Style applies to any Scenes using the same style.

Yes, I saw that post (Set rendering option "SectionCutDrawEdges" to false - #6 by DanRathbun) .

Yes, I need to use different styles in different scenarios, but I cannot add a style based on the current style.
The API only allows adding a style through a style file.
Sketchup::Styles#add_style-instance_method

I hope to add a style based on the user’s current style that only turns off section display and section cutting.

And I also hope to have this option when updating page.
image

Then load the “Default Styles/Default Style” style …

Sketchup.find_support_file("00Default Style.style", "Styles/Default Styles")

… rename it (and perhaps change the description), …

Then copy the style attributes (as needed) from the user’s current style to the new style by doing what I said above. Then make your changes to the user’s current style, then …
Set the new style to the selected_style and call styles.update_selected_style.
Then undo your changes to the current style.

Lastly use the new style by setting a scene to use it.

1 Like

Thank u.
How to get the file of style used by the current user?
It may be self-made

This is not yet exposed to the Ruby API. The C API does have this however.

I opened an API request back in DEC 2019 …

Sketchup::Style#path() · Issue #389 · SketchUp/api-issue-tracker (github.com)

… please add your comments, desires & use cases in that API issue thread.

1 Like
Sketchup.find_support_file("00Default Style.style", "Styles/Default Styles")

returns a string.

I can do:

styles.add_style(Sketchup.find_support_file("00Default Style.style", "Styles/Default Styles"), true)

But that does not return the new style. And even if it did, I don’t see how to modify the rendering options on that style.

Like the OP, I can create the correct rendering options in the view, but I can’t save them to a page.

Is there a more complete example anywhere?

However, since you used true as the 2nd argument, the selected style will be the style that was loaded.

styles = Sketchup.active_model.styles
style_path = Sketchup.find_support_file("00Default Style.style", "Styles/Default Styles")
styles.add_style(style_path, true)
new_style = styles.selected_style

I explained it above in several posts.

You will need to use styles.update_selected_style
And set the page to use your new modified style.

I don’t know.

Here’s an example that creates a page highlighting what the user has selected, sets the background to all white, and changes the camera to a ‘2D’ look. My intention is to use this page view in layout. Note that the style name change does not work in this example - don’t know why.

def set_page_rendering_options
    model = Sketchup.active_model
    styles = model.styles

    status = styles.add_style(Sketchup.find_support_file("00Default Style.style", "Styles/Default Styles"), true)
    my_style = styles.selected_style
    my_style.name = "My Style"

    pages = model.pages
    my_page = pages.add "My Page"

    selection = model.selection
    view = model.active_view

    camera = Sketchup::Camera.new
    camera.perspective = false
    up = camera.up
    up.set!(0, 0, 1)  # level
    target = camera.target
    target.set!(0, 0, 45) # parallel to y axis
    eye = camera.eye
    eye.set!(0, -1000, 45)
    camera.set(eye, target, up)
    view.camera = camera
    view.zoom(selection)
    model.rendering_options["DrawHorizon"] = false
    model.rendering_options["BackgroundColor"] = "white"

    styles.update_selected_style
    my_page.use_style = my_style
    status = my_page.update
    pages.selected_page = my_page
end

Hmmm… weird. I had to do some testing to find out why.

It seems that you cannot rename a style (or perhaps a default style) whilst it is the selected style.
If you do it gets reverted back to the default name. (FYI, default names are transparently square bracketed.)

ADD: The “active style” is the current rendering options being shown. Any changes are discarded when the selected style is changed, so the selection of my_style must be made after renaming but before changing rendering options.

This seems to work:

def set_page_rendering_options
    model = Sketchup.active_model
    styles = model.styles

    path = Sketchup.find_support_file("00Default Style.style", "Styles/Default Styles")
    status = styles.add_style(path, false)

    my_style = styles["[Default Style]"]
    puts "my_style:#{my_style.name} #{my_style.inspect}"
    my_style.name= "My Style"
    puts " renamed:#{my_style.name} #{my_style.inspect}"

    styles.selected_style= my_style

    pages = model.pages
    my_page = pages.add "My Page"

    selection = model.selection
    view = model.active_view

    camera = Sketchup::Camera.new
    camera.perspective = false
    up = camera.up
    up.set!(0, 0, 1)  # level
    target = camera.target
    target.set!(0, 0, 45) # parallel to y axis
    eye = camera.eye
    eye.set!(0, -1000, 45)
    camera.set(eye, target, up)
    view.camera = camera
    view.zoom(selection)
    model.rendering_options["DrawHorizon"] = false
    model.rendering_options["BackgroundColor"] = "white"

    styles.update_selected_style
    my_page.use_style = my_style
    status = my_page.update
    pages.selected_page = my_page
end
1 Like

Thanks, Dan. That worked perfectly. Same for style.description.