Evaluate Grashopper document without UI

Hello,
I am developing RhinoCommon plugIn that should be easily extended with Grasshopper components.

My idea is, that Rhino plugIn will provide geometry data, Grashopper will do some transformation and returns the result back.
Both parts are ready and they already communicate through shared project. What I would like to achive is the ability to first prototype the Grashopper document, then save it and later be able to evaluate it without Grashopper UI.

I was able to load Grashopper and open the test document prom the plugIn, but when I wasn’t able to do it without the grashopper editor being open. Is there some way how to do it?

_grashopper = RhinoApp.GetPlugInObject("Grasshopper") as GH_RhinoScriptInterface;
var success = _grashopper.OpenDocument(testFilePath);

Thanks in advance!

Hello @Kirchner_Honza

Yes, I use David’s code that I adapt to my needs:

jmv

Thanks, though, from a quick look it seems the post deals with different issue.
It provides a GH script that is able to run another GH script. What I need is to run GH script from within Rhino C# plugIn without visualy showing grashopper window.

Open it! The code allows to execute a GH file in C#. C# in Grasshopper, C# in Rhino, C# in a UI thread or C# in whatever…

But can I open it under the hood? I would like to only execute the file without showing Grashopper canvas. But OpenDocument function displays it no matter what I do.

Or do you mean something else by ‘Opening it’?

I am not exactly sure hich method here fits you situation.

Hops calls a headless Rhino to solve itself. It is open source so you can see all the methods we use: The Hops Component with Grasshopper

You can communicate with the local headless Rhino service that comes with Rhino 7 or do it online with Compute. Compute also has a protocol to send geometry a Grasshopper set of definitions and get results back from the process.

If you want to setup the project with a Rhino plugin that can call out to solve a Grasshopper definition without Grasshopper running then you can setup this style of project: Calling Compute with .NET with Csharp

And there is of course Grasshopper Player that will run Grasshopper definitions in the background: Rhino - Grasshopper Player

Or, there is also the ability to call Grasshopper components in a C# plugin without Grasshopper: Node in Code from Python. with Python

To add fuel to the fire there are many ways to use this tech:Bridging Data Science and Architectural Practice | by KPF Urban Interface | Jan, 2022 | Medium

1 Like

Amazing, thank you for exhaustive summary!

Solutions based on Compute look amazing. I am just not sure at this pint it’s worth for me to set up a server with Compute instance.

No matter what way I’ll choose in the end, this post really helped to realise the options I have.

Hello Scott, I have one extra question. Is it possible to execute any of those options you described on background thread? I quess it would be easily doable with Rhino.Compute, but if possible, I would like to do everything locally.

Yes, it is always on another thread.

The problem is that I have custom GH components that subscribe to events from my Rhino Plugin. The current workwlow is:

  1. When Rhino loads, I execute RunAsCommand for each of my GH documents I want to evaluate.
  2. When something in Rhino changes, event is emited and GH components receive fresh data

Even if I try to call both RunAsCommand function and the invocation with new data, Rhino’s UI is blocked. That’s something I would like to avoid.