Communication between Python with Hops and Rhino3dm.js

Hello everyone,

I’m working on a Python application using rhino.compute, where I’ve implemented a Grasshopper Hops definition to generate Rhino geometry. My goal is to visualize the 3D geometry and enable interaction within the application. To achieve this, I plan to use the rhino3dm.js library for visualization in Three.js and embed the viewer in the Python application.

I’m wondering if it’s possible to send a request to the Hops component from Python and receive the results in JavaScript, given that both are listening at “http://localhost:6500/”. I’ve searched extensively but haven’t found clear answers on this. If anyone has experience or advice on such a setup, I’d greatly appreciate your insights.

Thank you!

Anuj

@AndyPayne @fraguada
Apologies for tagging, but any advice on this topic would be really helpful.
Thanks

Hi Anuj. I guess I’m really confused about your setup and what you’re trying to do. Typically, Hops is the client and it sends requests to rhino.compute (ie. the server). The server performs the calculation and sends data back to the client. The client doesn’t have to be Hops. It can be anything that can send an HTTP request. So, a python application would be fine. But I’m confused when you say “both” are listening at http://localhost:6500/. Typically, only one application can open a port at any given time so I don’t think you can actually have two servers listening on the same port. Plus, I’m not entirely sure why you would want to do it in the first place. I guess I’m not entirely sure why you need Hops at all. Why not have your python application send requests to the rhino.compute server and then process the responses it gets back from the server. Would that work?
Also, this isn’t exactly an answer to your question… but there is a project called the App Server which uses rhino3dm.js and three.js to visualize some things in the browser. It’s mostly written for the web so it mostly uses Html and javascript, but maybe it can be useful for your project?

Hi Andy

Thanks for replying so promptly. You are absolutely right. I was mistaken. I wanted to write Rhino.Compute server and not Hops.

To simplify my question, My python application is sending requests to the Rhino.Compute Server and receiving the response back. This works fine without any issues.

What i want to achieve is to somehow send the request from python and receive the response in JS instead of python. Is this possible and do we have any example of this?

Thanks
Anuj

I think the short answer is no… or at least not without a lot of complication. I believe you would have to write your own custom endpoint which would receive your request from your python application… it would process it and then it would have to establish a different HTTP client and send a new request to whatever IP/port that your JS server is listening on. We definitely don’t have an example of this sort of setup. If it were me, I would look into the App Server repo that I posted above. I think it may do a lot of what you’re looking for. In the App Server, The javascript client makes the request to a nodejs server. The nodejs server makes the request to rhino.compute. Then, the nodejs server receives the response, and passes the response back to the javascript client. I think all you would have to change in this sort of setup is replacing the javascript client with your python client.

great. thanks for the reply Andy.
I will try what you are suggesting. At least i have a way forward. :smiley:
Thanks again