Grasshopper Button Should I expire solution?


I added a button to grasshopper component following @DavidRutten old posts.
When I click on it, it is not changing unless I press again somewhere on canvas. For this reason I added baseClass.ExpireSolution(true) line 45.
But I am wondering if this actually correct to expire the full component to change its preview?

If the graphics depends on the solved state then you have to expire solution, but if you only needs to redraw the graphics, I think this does that:

and I guess you have to call canvas.Refresh() or canvas.Invalidate() after that.

1 Like

It seems that this works:


And after I change the state of the button I would like to rerun solve instance.
Where it is better to place expire solution in that case?

Use Invalidate() or Refresh(), not both. I would use Refresh().

I guess that expire solution schedule a new solution for when the current finish, so in that case doesn’t matter where you call it. I would put it in the button click event handler.

Thanks, you mean inside function:
RespondToMouseDown ?