Clear display memory once there are no inputs - Grasshopper Component Display


#1

Hi,

I have an issue with Grashopper Preview made in custom class. I use this class in many component by inheritence, such as:
public class OffsetMeshVDA : GH_Component_NGon
I attached the file. The issue is that when I remove the wires from the component the preview of the last input is still visible.

Would be it be possible for someone to take a look at .cs file, I think I have some obvious mistake that I cannot find?

GH_Component_NGon.cs (7.2 KB)


(David Rutten) #2

So the issue is you’re (re)building preview geometry during SolveInstance() which you then draw, but when an input is disconnected the SolveInstance() method is never called because the input isn’t optional?


#3

That is right, now I made all inputs optional.

But how to “force” the component to call the method when component inputs are empty?
Because when component goes orange, solve instance is not called. I suppose.

Currently in other components solve instance I always type this method: base.PreparePreview(some geometry to preview).

But in case nothing is inputted how to clear the preview?


(David Rutten) #4

That may not be the best solution. Inputs should only be optional if they are truly optional. I.e. if your component can run without them.

You should erase your preview caches inside the BeforeSolveInstance() method. This method is always called and only called once per solution, so it’s a good place to do preparatory work.

ps. if your component is disabled (Locked == true), then BeforeSolveInstance() won’t run.


#5

Cleaning collections in BeforeSolveInstance does the trick, thank you very much.