How to run a Grasshopper script with Rhino Inside in a WinForm component

We have a simple script that gets a param as input. After that if does some calculation and makes some changes.

What we need to do is to somehow pass the input to that param from a winform and make sure the script starts and runs.

How can this be done with this tech?

Is there something like:

var grasshopperScript = new GrasshopperScript("Path to the script);
var scriptInputs = new list of inputs
List<GH_Output> = grasshopperScript.Run(scriptInput);

I wish we had that syntax!

For now, maybe it would be useful to check out how RESThopper takes a .ghx file, sets input parameter values, and calculates output? ( Code Here ) If you know for sure what kind of geometry you’re dealing with you should be able to cut out most of the code there.

Happy to clarify anything

Hey Chuck,

Thanks for the quick reply. Im working with harri on this one.

I have an extra question, perheps you can help us.

This grasshopper script that we will run is actually having some components inside that after the calculations compute it connects to the software Tekla structures and create native objects within that software.
If we run this script with this method would this link with tekla structures be kept?

I’ve never seen it done, but it should? In theory, anything you can do on that machine manually in grasshopper can also be done by RESThopper (unless you need visible/viewport information).

What’s the best resource for Grasshopper/Rhino in C# for finding out how to properly start the Rhino process, find wanted GH input parameters, apply new values, find wanted outputs, read their values and then end the Rhino process?

I’ve managed to get the process going, find inputs according to their nicknames and set some primitive values. It’s a bit unclear to me when the outputs are actually computed, do I have to go through them and do stuff like CollectData() and ComputeData()? And when do I need to set persistent data and when volatile? (Some of this stuff is probably really GH basic)

1 Like

I’m not sure there’s much information out there, you’re kind of at the bleeding edge.

It sounds like you’re doing it right, though. Outputs are computed when you call CollectData() and ComputeData() as far as I know.

What do you mean by persistent data? If you’re talking about .AddVolatileData() calls like this one, I think it’s our only option for settings values.

You can also call SetPersistentData on parameters, and it confuses me a bit as I thought persistent data means something “constant” in the script like a number input and volatile something calculated.

But it seems you can just set both volatile and persistent data on some script element. So it’s hard to tell what’s the correct way. Also, the set values seem to accumulate on the parameter which I find odd. E.g. if I have a number parameter which already has a value set in GH and I set a value in code I can see both values when debugging like a parameter can have multiple values. And correspondingly outputs coming from those parameters will have multiple values as well. I guess this is something in GH that I don’t understand.