How to redraw the object created by customdisplay?

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

def customDisplay(toggle,component):
    
    """ 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
    st[displayGuid].Clear()
    
    # Return the display or get rid of it
    if toggle:
        return st[displayGuid]
    else:
        st[displayGuid].Dispose()
        del st[displayGuid]
        return None

def killCustomDisplays():
    
    """ Clear any custom displays living in the Python sticky dictionary """
    
    for k,v in st.items():
        if type(v) is rc.Display.CustomDisplay:
            v.Dispose()
            del st[k]

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 DrawViewportWires and DrawViewportMeshes methods, which would negate the whole CustomDisplay business in the first place (which isn’t possible with the dynamic GHPython component).

5 Likes