Custom Preview - Draw Order / Draw Foreground

Okay, I went back to some previous posts @AndersDeleuran shared such as this one:

And figured it out.

Here’s the updated Python code if anyone is interested:

from ghpythonlib.componentbase import executingcomponent as component
import Grasshopper
import System
from System.Drawing import Color
import Rhino as rh

class CustomDisplayForeground(component):

    def RunScript(self, O, M):
        # M is a list of meshes
        self.meshes = O  

        # Set Display Color
        self.material = rh.Display.DisplayMaterial(Color.Black)
        self.material.Emission = M

    #Setup Objects To Be Drawn
    def DrawForeground(self, sender, arg):
        if self.drawingWires:
            self.drawingWires = False

        for mesh in self.meshes:
            arg.Display.DrawMeshShaded(mesh, self.material)

    def DrawViewportWires (self,arg):
        self.drawingWires = True

    #Handle Draw Foreground Events
    def __exit__(self):
        rh.Display.DisplayPipeline.DrawForeground -= self.DrawForeground
        
    def __enter__(self):
        rh.Display.DisplayPipeline.DrawForeground += self.DrawForeground

Model Space:

image

1 Like