Grasshopper Button Should I expire solution?

Hi,

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:
https://developer.rhino3d.com/api/grasshopper/html/M_Grasshopper_Kernel_GH_Attributes_1_ExpireLayout.htm

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

1 Like

It seems that this works:

            ExpireLayout();
            sender.Refresh();
            sender.Invalidate();

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 ?