Running a Grasshopper solution

I’m trying to run a Grasshopper solution from LinqPad but it never seems to do anything.

async void Main()
    var core = startRhino();
    core.Run();  // Is this needed?
    var arch = new GH_IO.Serialization.GH_Archive();

   doc = new GH_Document();
   using (doc)
       if (!arch.ExtractObject(doc, "Definition"))
          throw new Exception();

       doc.SolutionStart += solutionStart;
       doc.SolutionEnd += solutionEnd;
       doc.ScheduleSolution(0, scheduleDelegate);	

Per advice given elsewhere I set input parameters in scheduleDelegate and compute outputs in solutionEnd.

But solutionStart, solutionEnd and the scheduleDelegate never get called and the LinqPad script just exits. Is scheduleSolution starting the solution in another thread and my script exits before it gets to do anything. I did try polling ScheduleProgress but it always remained at 0.

Am I missing something here or is this completely the wrong way of going about this? There doesn’t seem to be any documentation on the matter.

Hi @harri.ohra-aho,

There is a good example of how to accomplish this in Rhino Compute code as the grasshopper endpoint.

This essentially does what you’re trying to do as well.

Here is the initial bare-bone implementation by @will:

The important part here is that you don’t have to execute the definition separately. After injecting your own input data you should only have to find the output parameter that you are ultimately interested in and call CollectData() and ComputeData() on it. Grasshopper should figure out what needs recomputing on its own based on that.

A more complete implementation you can see in the current implementation that has been fleshed out quite a bit.

See comment // Set input params and // Parse output params. Note the use of AddVolatileData() instead of SetPersistentData().

So in the end you don’t need to use SolutionStart, SolutionEnd and ScheduleSolution.


Ok, thanks. I guess the first way I tried this was actually correct then.