Hello, I am testing Rhino Compute and Grasshopper definition, but I could not make the server load the GH definition.
My server setup and GH definition are extremely simple.
Can anyone please let me know how I make this connection work?
---------------- server.py
from flask import Flask
import requests
import urllib.parse
import json
import os
app = Flask(__name__)
@app.route("/test_compute")
def test_compute():
# Absolute path to GH file
gh_path = r"D:\Desktop\aa.gh"
if not os.path.exists(gh_path):
return f"Error: GH file not found at {gh_path}"
# Encode for URL
encoded_path = urllib.parse.quote(gh_path.replace("\\", "/"))
url = f"http://localhost:5000/grasshopper?pointer={encoded_path}"
# Prepare input for parameter "x"
payload = {
"x": 5
}
try:
print(f"Calling Rhino Compute: {url}")
res = requests.post(url, json=payload, timeout=30)
res.raise_for_status()
return json.dumps(res.json(), indent=2)
except Exception as e:
return f"Failed: {e}"
if __name__ == "__main__":
app.run(port=3000)
---------------- error message
CG [12:05:27 DBG] Received a HTTP POST request to the /grasshopper endpoint CG [12:05:27 WRN] Unable to load grasshopper definition CG [12:05:27 ERR] Connection id "0HNBTRRMN8SH0", Request id "0HNBTRRMN8SH0:00000001": An unhandled exception was thrown by the application. System.Exception: Unable to load grasshopper definition at compute.geometry.ResthopperEndpointsModule.GrasshopperSolveHelper(Schema input, String body, Stopwatch stopwatch, HttpContext ctx) in D:\Desktop\Git\compute.rhino3d\src\compute.geometry\ResthopperEndpoints.cs:line 83 at compute.geometry.ResthopperEndpointsModule.Grasshopper(HttpContext ctx) in D:\Desktop\Git\compute.rhino3d\src\compute.geometry\ResthopperEndpoints.cs:line 174 at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication
1 application)
`