Hacking the Grasshopper Hops Component

Hops is meant to let you re-use of Grasshopper script parts across multiple documents, and consume Rhino Compute services that are hosted online or on a local network. It provides a single component, that when given a path to a local file or network endpoint, turns itself into a component representing the function and handles communication with the source. That is, it shows a new icon, sets up the appropriate inputs and outputs, makes requests and returns responses either to a local file or remote service.

Besides making calls to other local Grasshopper documents, and remote Rhino Compute servers, Hops also works with any Flask-based Python1 server that uses the rhino3dm python library, through a REST API. An example is included in the Rhino Compute repository. This is great because it provides a way to use "real" Python, independent of the Rhino application, incorporating third-party libraries like NumPy, using your preferred editor etc2.

But what else can it be used for? One potential opportunity here is you could hypothetically build a single API accessible from either Grasshopper or a web app. Even though this use case isn't documented, you don't actually need Rhino Compute or rhino3dm on the server to use Hops. Given that the Hops code is open-source, you could go as far as adapting the code to use a properly open format like well-known binary rather than openNURBS for the geometry representation, making it easier to work with geospatial libraries like shapely, but let's leave that for another time.

Using the Hops Grasshopper component as-is, can we adapt the server example to work without using any Rhino-specific code? Here's what I did:

98021aba30938ddf.png

Footnotes:

1

Specifically, CPython (not the IronPython provided by Rhino/Grasshopper)

2

Rhino 8 offers new Python 3 features and an improved editor, I haven't looked closely at the implications of this yet.