How to clear the display cache in GH_component

Hello all,

it seems like a very simple question, but I have had problems to clear the display cache of my GH_component. I know i need to override the clearData method but honestly, I don’t know where to invoke it and what method? base.ExpirePreview(true);
I invoked these three methods in SolveInstane() at the beginning of everything, doesn’t work, I did it in BeforeSolveInstance() it does not work either. I really appreciate it if any of you could direct me to a right direction.


There is no display cache by default. All previews are drawn from the currently computed data.

Are you talking about the Rhino viewport display or the Grasshopper canvas display?

Thanks david for your quick response, my component draws some geometry with custom color I assigned to via overriding DrawViewportWires, but whenever i change the input parameters of the component, the previously made geometry stays on rhino screen , i need to clear the display cache as far as i understand, but havent been able to do it properly

tried to follow the steps here Seting a Brep color but as you mentioned there , it is different in GH_Component than c# script, I dont know where and how to clear the cache in visual studio GH_Component

Assuming you have some fields where you store the geometry (and materials…):

private List<Brep> brepCache;
private List<Color> colorCache;

which you read them in DrawViewportWires(), in SolveInstance try doing this:

 if (DA.Iteration == 0) { 
    brepCache = new List<Brep>(); //Or call .Clear() if they are instantiated.
    colorCache = new List<Color>();

brepCache.Add(... //Add your geometry

I suppose you should also overwrite DrawViewportMeshes and DrawViewportWires and not call the base method from the inside, to prevent GH from drawing by default. Try and see if it works.


Thanks Dani,

That was it, i just needed to clear the lists, never thought of that. I thought i need to clear the display cache.
Thanks again.

1 Like