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