The approach I generally use is to clear the custom display each time the component runs. In GHPython, I stick a persistent custom display into the sticky dict (enabling one to kill any stray/forgotton displays), using these two functions (that I import from a general GHPython utility module I’ve been developing):
import Rhino as rc
from scriptcontext import sticky as st
""" Make a custom display which is unique to the component and lives in sticky """
# Make unique name and custom display
displayGuid = "customDisplay_" + str(component.InstanceGuid)
if displayGuid not in st:
st[displayGuid] = rc.Display.CustomDisplay(True)
# Clear display each time component runs
# Return the display or get rid of it
""" Clear any custom displays living in the Python sticky dictionary """
for k,v in st.items():
if type(v) is rc.Display.CustomDisplay:
In C# I assume one could instantiate a display as a static variable in a similar manner (i.e. if it exists, clear it each time the component runs). Although, you could also just overwrite the
DrawViewportMeshes methods, which would negate the whole
CustomDisplay business in the first place (which isn’t possible with the dynamic GHPython component).