Expiring multiple components in the GH Canvas

Hi all, I’m trying to expire multiple components on my canvas (from another component)

One way to go about it is the below code


var doc = Grasshopper.Instances.ActiveCanvas.Document;
                foreach (Grasshopper_LinkajouTemplateWithFlags obj in doc.Objects.OfType<Grasshopper_LinkajouTemplateWithFlags>().Where(o => !ReferenceEquals(this, o)))
                {
                    if(obj.Country != country)
                    {
                       obj.Country = country;
                       obj.ExpireSolution(false);
                    }
                    
                }

                OnDisplayExpired(true);

However it looks to me like it’s more lightweight to set the objects to BLANK ?
if multiple of these components are connected, it might expire the most downstream first and then it will re-run when i expire the more upstream. Is there a way to mark them all to blank and then force rerunning all BLANK items. And in that case how would that code look like?

Best, Mathias

Maybe I don’t understand your question correctly,
but since you are using False for the recompute argument in obj.ExpireSolution(recompute), the order at which the ExpireSolution is called on the components doesn’t matter.

The recomputing of the canvas won’t start until triggered from elsewhere, at which point the Grasshopper will follow the “optimal” order of solving the components on canvas (no component will get solved before all components that are upstream from it and are marked as expired are solved first).

Thanks for the reply ! In that case I can obj.expireSolution(false) on all of the components but then how do I start the chain of solving them?

You can either wait until any other event schedules a solution (almost anything on the canvas changing will trigger this), or schedule it manually - there are multiple ways to do this, but the best bet is:

Grasshopper.Instances.ActiveCanvas.Document.ScheduleSolution(10)

or

Grasshopper.Instances.ActiveCanvas.Document.NewSolution(false)
1 Like

Thanks a bunch!