How to turn off ground plane using python

Hey all, I don’t understand why the following code below will not turn off the ground plane for my rendering. Let me know if I miss anything. Thanks!

        settings = self.document.RenderSettings
        prev_ground_plane_enabled = settings.GroundPlane.Enabled

        settings.GroundPlane.Enabled = False

        self.document.RenderSettings = settings

        temp_dir = tempfile.gettempdir()
        random_filename = str(uuid.uuid4()) + '.png'
        file_path = os.path.join(temp_dir, random_filename)

        Rhino.RhinoApp.RunScript("_Render", True)
        rhinoscriptsyntax.Command("-_SaveRenderWindowAs \"{}\"".format(file_path))
        Rhino.RhinoApp.RunScript('_CloseRenderWindow', True)

You don’t need to do self.document.RenderSettings = settings. Instead you need to bracket the place where you change the status with BeginChange and EndChange method calls:

settings.GroundPlane.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Program)
settings.GroundPlane.Enabled = False
settings.GroundPlane.EndChange()
2 Likes

Thank you Nathan, is BeginChange/EndChange only required for GroundPlane settings? I also changed the following settings and they seem to work.

        settings.ImageSize = ...
        settings.UseViewportSize = False
        settings.TransparentBackground = True
        settings.SpecificViewport = viewport_name

Not all data requires that. You can always refer to the documentation to see if a class you are accessing has BeginChange / EndChange. If it does you know it needs that:

1 Like

I just realized this property does not exists for Rhino 7. Is the anyway to do this for Rhino 7? Thanks!

Hmm just saw this: RhinoDoc.GroundPlane Property

That is the way for older versions since Rhino 5.

1 Like