Component.ExpireSolution, documentation?

Hello all C# learners !

I did this C# script but I don’t understand, why this code only works when double count is inside the // Custom additional block of code ?

I would like to have a better understanding about Component.ExpireSolution any suggestion where to look at?

Where to find documentation about the Component.ExpireSolution?

Thanks!

conditional-reset-startStepEnd.gh (11.9 KB)

 private void RunScript(bool reset, double start, double step, double end, ref object A)
  {
    if((start < end) & (step > 0))
    {
      if (reset){
        count = start;
      }else{
        if(count <= (end - step))
        {
          //count++;
          count = count + step;
          Component.ExpireSolution(true);
        }
      }
    }
    A = count;
  }

  // <Custom additional code> 
  double count;
  // </Custom additional code> 
}

If you want to make a loop, don’t call ExpireSolution in SolveInstance/RunScript. Call it in AfterSolveInstance

1 Like

You are changing the expiration flow of GH by forcing the expiration while the component (and solution) is being made. Instead, you have to tell the document to re-solve and expire the component then. Replace GH_Component.ExpireSolution() with GH_Document.ScheduleSolution() method.

You have to put the count variable outside the body of RunScript, as a global variable within the Script_Instance class context, because this is the method that is called into the loop you are making. If the variable is initialized inside RunScript, each time it’s called it’s restarted. But if you have it outside, it only initializes once.

private void RunScript(bool reset, double start, double step, double end, ref object A)
{

if((start < end) & (step > 0))
{
  if (reset){
    count = start;
  }else{
    if(count <= (end - step))
    {
      //count++;
      count = count + step;
      //Component.ExpireSolution(true);
      GrasshopperDocument.ScheduleSolution(10, ScheduleSolutionCallback);
    }
  }
}

A = count;

}

// <Custom additional code> 
double count;

public void ScheduleSolutionCallback(GH_Document doc)
{
  this.Component.ExpireSolution(false);
}
// </Custom additional code> 
}
3 Likes

Thanks Dani Abalde for your explanation!
Best!