Triggering a new solution

I am messing about with creating a pair of components that can pass data backward (i.e. the component downstream influences a component upstream).

This is how it looks:

Input2 for component C2 gets the number from the slider and passes it on to static class, which is in turn accessed by component C1 to be outputted at Output2.

To achieve this the pair of components have to be solved twice:

  • First iteration: Get the number from the input of the C1 component and sets it as Output1. The C2 component gets both of the inputs and updates the variable of the static class. The Second iteration is triggered.

  • Second iteration: C1 component gets the variable from the static class and outputs it as Output2 as well as outputting the Input number to Output1. C2 just outputs the number it got from C1.

The problem I face is for some reason I cannot trigger a Second iteration/solution from within the script. I have tried calling ExpireSolution(true), GH_Document.NewSolution(true) and even GH_Document.ScheduleSolution(), but I cannot get Grasshopper to re-calculate the solution.

Everything works fine is I manually click Recompute in Grasshopper.

Does anyone know why this could be happening?

Communicator.cs (323 Bytes) Component1.cs (4.0 KB) Component2.cs (2.9 KB)

Figured it out.

In the SolveInstance method of component C2, you need to call ExpireSolution(true) method of the C1 component. First you’ll need to find it in the GH_Document.Objects ( you can find it by it’s nickname).

Then you have to overide the AfterSolveInstance method of the C2 comopnent and add a ScheduleSolution() method.

Communicator.cs (382 Bytes) Component1.cs (4.1 KB) Component2.cs (4.0 KB)

Communication_Test.gha (6 KB)