Help: Create new environment with Common

Hi, I want to create a new (black) environment and set it as active for all channels, do some view capturing and set the old values back, but I can not figure out how to do so.
I have gotten to the point where I am to sett the different environment channels, but there I am at a loss:

import Rhino
import scriptcontext as sc
import System
import rhinoscriptsyntax as rs

color = rs.coercecolor((0,0,0))
sim = Rhino.Render.SimulatedEnvironment()
sim.BackgroundColor = color
env = Rhino.Render.RenderEnvironment.NewBasicEnvironment(sim)
env.Name = "My_environment"
print (env.Name)

index = sc.doc.RenderEnvironments.Add(env)
if index == True:
    print (env.Id)
    # Set for all environment channels

I wrote an example of how to create an HDRi environment here: https://jesterking.github.io/rhipy/create_hdri_environment.html

Oh, you also want to change render settings so you can set background, reflection and skylight environments. I have some code I use in a huge regression testing script where I set these. Let me dreg that up from the depths of my storage.

Sweet, thanks, I should be good to go from there then. This stuff is getting more and more complex for an novice to handle, but better for the users so I guess we should be happy :slight_smile:

raytraced.zip (13.1 MB)

Here a script with which I generate several hairs short of 1000 tests with different environment options. In this script I do import existing environments, but what you should look at is how to change the document render settings to set background, reflection and skylight environments. This happens in prepare_model method from line 266 onward in regression.py, specifically between lines 305 and 334, replicated here for convenience:

            # set bg
            bgsettings = self.bg_settings()
            rendersettings = doc.RenderSettings
            rendersettings.BackgroundStyle = bgsettings[0]
            if bgsettings[0] == bgstyle.Environment:
                #print("setting environment to", bgsettings[1])
                doc.CurrentEnvironment.ForBackground = get_renv(bgsettings[1])
            else:
                doc.CurrentEnvironment.ForBackground = None

            # set custom reflection
            reflsettings = self.refl_settings()
            if reflsettings[0]:
                doc.CurrentEnvironment.ForReflectionAndRefraction = get_renv(reflsettings[1])
            else:
                doc.CurrentEnvironment.ForReflectionAndRefraction = None

            # set skylight
            skysettings = self.sky_settings()
            skylight = doc.Lights.Skylight
            skylight.BeginChange(programContext)
            skylight.Enabled = skysettings[0]
            skylight.EndChange()
            if skysettings[0]:
                skyenv = get_renv(skysettings[1])
                print("setting sky env {0} [{1}]".format(skysettings[0], skyenv))
                doc.CurrentEnvironment.ForLighting = get_renv(skysettings[1])
            else:
                print("no sky")
                doc.CurrentEnvironment.ForLighting = None
1 Like