How to redraw the object created by customdisplay?

 Rhino.Display.CustomDisplay display = new Rhino.Display.CustomDisplay(true);
 display.AddPoints(pL, clr, Rhino.Display.PointStyle.X, radius);

above is the code from c# in vs.
when I intend to display some object in viewport,i use display.addXXXX,but ,everytime after creating,when I moving the objects,the older objects on viewport remains on the viewport,it seems no good…
how to refresh or redraw the viewport?thankyou.

The custom display keeps local copies of the geometry it draws. If you change the geometry, you have to create a new 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
    # Return the display or get rid of it
    if toggle:
        return st[displayGuid]
        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:
            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).


Hi @AndersDeleuran.
I manage to implement your python script but unfortunately I found a little problem that I couldn’t solve.

I am developing a tool with 4 components that wants to visualise curve and vector in the display. I would like to avoid the user to automatically kill the display.
Is there anyway to implement something like Human?

Indeed, you can now call the DrawViewportWires method (in SDK mode):

1 Like

I knew it that you would have the solution :slight_smile:
Thanks @AndersDeleuran. Really appreciate the help that you are giving to the Ghpython Community :smiling_face_with_three_hearts:

1 Like