Hey all, I’m getting confused on how to turn off the reflection in the current environment using Python for Rhino 7 & 8. I found the RenderEnvironment
in ICurrentEnvironment.ForReflectionAndRefraction
, but how do I turn it off like the new API RenderSettings.SetRenderEnvironmentOverride
?
Thanks!
Disabling reflection environment will not solve the problem of specular/fresnel reflection from your other thread. That is only meant for setting a different environment to use for reflections of the environment than what the main environment is.
Yup that’s alright. Either way, I do not want reflections in the rendering. Could you show me how to do it in Python?
I already told you that if you don’t want reflections you need to use materials that are diffuse (turn up roughness to 100%).
Disabling the custom reflection environment you do by just passing null
(None
in Python)
The documentation says so too: ICurrentEnvironment.ForReflectionAndRefraction Property
… If setting, passing null will turn the custom reflection environment override off …
Anyway, on RenderSettings the better usage is RenderSettings.SetRenderEnvironment Method
import Rhino
import scriptcontext as sc
# lots of code
sc.doc.RenderSettings.SetRenderEnvironment(Rhino.Render.RenderSettings.EnvironmentUsage.Reflection, None)
Ah got it. Thank you so much Nathan.
SetRenderEnvironment
only supports on Rhino 8 Just want to double check, is this how you should set it for Rhino 7?
self.document.CurrentEnvironment.ForReflectionAndRefraction = None
That would be correct yes.
I think that freezes the script editor on Rhino 7, but works for Rhino 8.
logger.info("before")
self.document.CurrentEnvironment.ForReflectionAndRefraction = None
logger.info("after")
On Rhino 7, the after print statement is not getting print. Thanks!
I am not sure why the setter doesn’t work. The ICurrentEnvironment interface defines both getter and setter yet an error message saying that you can’t set is given.
It works when used from C#. There is probably some deep issue going on in the IronPython integration for which I don’t think there will be any fixes done in Rhino 7 anymore. The last release of Rhino 7 for a critical issue was back in May 2024 (Rhino 7.37).
Thank you for the video. With some searching on the forum, it sounds like we can do it via scripting.
import Rhino
s = "_-DocumentProperties _Render _Background _UseCustomReflectiveEnvironment _Yes _EnterEnd"
Rhino.RhinoApp.RunScript(s, False)
The script here set the property, is there anyway we can get the property via scripting so we can restore this flag after we run the command?
Instead of _Yes you probably want _No (:
Anyway, you can use the ICurrentEnvironment to see if it is set and deduce from that what you need to do.
Awesome. i will give it a try! Thank you so much for all your help! They are super useful for someone who is completely new to Rhino
For more learning material on using rendering related classes (RenderContent mostly) please check out my literate programs: https://jesterking.github.io/rhipy/ - these try to explain and show the pitfalls associated with using these.
Sorry this might be another dumb question:
s = "_-DocumentProperties _Render _Background _UseCustomReflectiveEnvironment _Yes _EnterEnd"
If I understand correctly, the _Render component will tell Rhino to select the Render table under DocumentProperties. However, it seems like Rhino will just execute “DocumentProperties” and “Render” as separate commands. Therefore, the DocumentProperties panel will pop up then render command will be run. What did I miss? Thank you!
In fact, Rhino 8 doesn’t seem to work either using SetRenderEnvironment
. Even though I set it to None and the No Environment is set in the Rendering panel UI, the rendering still has the reflection.
However, if I manually change to No Environment from the UI, it works. It seems like SetRenderEnvironment
only update the UI, but it doesn’t change the underlying rendering settings.
settings = self.document.RenderSettings
settings.SetRenderEnvironment(Rhino.Render.RenderSettings.EnvironmentUsage.Reflection, None)
Rhino.RhinoApp.RunScript("_Render", True)
rhinoscriptsyntax.Command("-_SaveRenderWindowAs \"{}\"".format(file_path))
Rhino.RhinoApp.RunScript('_CloseRenderWindow', True)