Use a grasshopper file in the background to make an object

i need a rhino plugin in c# that loads a grasshopper or a cluster file (Cluster is better ) in the background, passes data to its inputs and gets the list of geometry base of its outputs.
can anyone give me a simple example code for that?
thanks,

Any Ideas?

Have you tried the Grasshopper Player? Rhino - Grasshopper Player

1 Like

thanks alot for the reply Luis,
actually that is exactly what I’m looking for, but as I have a rhino plugin, I want to pass “file path” Programmatically and get other “ClusterInputs” in a UI from the user, and as there will be several “ClusterOutputs” I want the user to choose between them and decide witch one to bake or even better, just get the geometry bases, I mean more control on Inputs and outputs.so If I could use GrasshopperPlayer in my rhino plugin like “RhinoApp.RunScript” but programmatically pass it inputs, and also programmatically get the outputs would work very nice for me.

Hmm. I’m not sure I am understanding what you want to do, so probably not a good idea to keep suggesting things, but maybe Hops could help? Rhino - What is Hops

1 Like

Thanks Luis, Hops was interesting, but not what I’m seeking of,besides I don’t want my user to even open the grasshopper, I want all of that to be done through a rhino plugin.

It sounds like you would like to write code that launches Grasshopper in a similar way to what Grasshopper Player does but without any user input and UI interaction so that you can programmatically use it to silently evaluate (calculate) a cluster in the background and return the output GeometryBase list of objects - is that right?

I’ve just done basic experimentation to discover how to silently launch Grasshopper, possibly similar to the way the Grasshopper Player does, but it’s incomplete:

var plugins = Rhino.PlugIns.PlugIn.GetInstalledPlugIns();
var ghGuid = plugins.FirstOrDefault(p => p.Value.Equals("Grasshopper")).Key;
Rhino.PlugIns.PlugIn.LoadPlugIn(ghGuid, true, true);

As well as this, adding Grasshopper.dll as a reference isn’t enough apparently as this kind of line:
var ghDoc = new GH_Document();
does throw an exception about other libraries needing to be referenced/loaded - but hopefully others can help out further.

1 Like

@arc.feizbahr This is an older sample, but it might shed some light as to how get the GH plugin object, load a gh definition, and solve the inputs. rhino-developer-samples/rhino.inside/dotnet/SampleRunGrasshopper/Program.cs at 8 · mcneel/rhino-developer-samples · GitHub

@AndyPayne and @kike might have some more up to date ways of doing what you want.

1 Like

Thanks @fraguada And also Thanks @nicolaasburgers .
I Found it !! :grin:
I will put it in a Public Github repository and post the link here.

1 Like

Great @arc.feizbahr, I look forward to it as I want to experiment with this approach, too. Cheers - Nic

1 Like