Turn a Grasshopper Script into Rhino Command (Headless Grasshopper)

Hi

Is there any way or were there any attempts to turn grasshopper scripts into Rhino Commands? This would be the best way to deploy them.

Why?

You can run a gh document from inside a command, the problem are the inputs and outputs. You can’t hook them properly from GH to Rhino, because they don’t support the features the other needs. If for example, your parameters are numbers or geometry and with item or list access, and if you have few scripts, I would recommend you to do it one by one, to ensure that all work and be able to detail them properly.

But generalizing this to make it automatic is complicated, because the scheme of inputs and outputs between GH and Rhino commands are too different and the data support has nothing to do with them. It might work if you restrict the problem a lot (like avoiding components with tree access parameters or just supporting certain types of data or sacrificing the text/info that helps the user understand the command), or if you create several interface windows to resolve certain issues, but then the question arises, if this is really worth it. It wouldn’t be nonsense to consider a different interface to solve this, instead of using the command line, more work, but less botched.

Some time ago I gave it a whole afternoon and got a proof of concept for a command that lets you call any gh component (just one, because I was going to use clusters to start with). It worked, but many non-obvious problems arose. The Rhino ecosystem doesn’t have a standard/multienvironment/multiuse scheme to define parameters, and this has already blocked me several times. Also keep in mind that I haven’t dedicated enough time to it and that there are probably more intelligent solutions than what I have tried. But what I do know is that both rhino and grasshopper are very limited in parameter support. For example, if you have a definition or document, which are the global inputs (source, in this case the ones you are interested in taking to a command) and which are the internal inputs? Within a component, which are the inputs that operate on the variable (geometry usually) and which are the inputs that modify the operation?..

Anyway, what really solves this? that rhino users can use a very small subdomain of the gh utility without knowing how to use gh? If you need two or three gh scripts as commands, it’s best to work on each one individually to restrict it and give the right messages to the user and all that.

2 Likes

To create a custom command in Rhino, you can implement a RunCommand method, compile it and then run it in Rhino.

See tutorial here: https://developer.rhino3d.com/guides/rhinocommon/your-first-plugin-windows/
and examples here: https://developer.rhino3d.com/samples/

For a Rhino command, you usually use the RhinoCommon API:
https://developer.rhino3d.com/api/RhinoCommon/html/R_Project_RhinoCommon.htm

I am note sure if it is possible (or if it makes sense) to also use the Grasshopper API for a pure Rhino command - because RhinoCommon provides all major geometric functionality and the Grasshopper API is more like a wrapper around RhinoCommon plus UI/canvas functionality.
https://developer.rhino3d.com/wip/api/grasshopper/html/723c01da-9986-4db2-8f53-6f3a7494df75.htm

For scripted GH components, you may most of the time also use the underlying RhinoCommon functions for Curves, Breps and so on.

If you require to access the functionality of specific Grasshopper components / library, you may include the corresponding libraries (.dll files) within Visual Studio for the implementation of a Rhino command.

In general, if you want to deploy a function you can do it through

  • a RhinoCommand
  • deploy the .GH file with the custom script python (that someone may copy into another GH file)
  • or build a custom GH component.

I would say it depends a lot on what you want to achieve and for what purpose you deploy that function.

Do you have any specific case / function in mind? I guess that would help to answer your question

1 Like