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 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).
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?