How to track back a previous Custom Display?

Hi, I just start learning C# to create custom components,
I want to reproduce a custom preview function in C# API,
and I’ve successfully draw curve or other geometries according to this source:
Rhino.Display.CustomDisplay and event handling using Python - Grasshopper (grasshopper3d.com)

But this function runs one-time only, so I can’t undo or remove the display untill I restart the program.

Is it possible to get all custom display class in the document?
or how can I delete or dispose all the previous custom display objects?

Thanks in advance :]

Finally found the answer thanks to this post :]

Seems like I have to construct the CustomDisplay class outside the function with static keyword.

How to redraw the object created by customdisplay? - Grasshopper Developer - McNeel Forum

1 Like

I was just about to reply, pointing this out. That said, I’d recommend overriding the DrawViewportMeshes and DrawViewportWires methods instead. It’s arguably simpler and enables you to call all the methods in the DisplayPipeline (i.e. unlike CustomDisplay):

And a GHPython example here:

1 Like