Geometry encoding for Compute

Could you show how you create this input data? I’ve got an error when I’m trying to pass Points using this method:

let x = new this._rhino.Point([-5, 5, 0]);
let dataD = {
      definition: "",
      inputs: { X: x.encode() },

    let jsonData = JSON.stringify(dataD);

    const request = {
      method: "POST",
      body: jsonData,
      headers: { "Content-Type": "application/json" },

When I create points as string like that:
'{"X":' + 80 + ',"Y":' + 200 + ',"Z":' + 0 + "}",
everything works fine…

Yes, that’s how you should be doing it.

Check out this sample:

Could you tell me how I should create more sophisticated objects like (for example) curve, polyline, polygon, etc. Is there any documentation about that?

Most of what we have online can be found here:

Yes, this repo help me a lot, but I didn’t find info how to sens for example curve to rhino.compute as RH_IN parametr using this convention like in example with Pointa.

Curves derive from the GeometryBase class and thus needs to be encoded to be sent to compute. Points and other structs are sent a bit differently. We’re still trying to work this out so it is less confusing. For a curve you could do:

const curvePoints = new rhino.Point3dList()
curvePoints.add( 0, 0, 0 )
curvePoints.add( 5, 5, 0)
curvePoints.add( 10, -5, 0 )
curvePoints.add( 15, 5, 0 )
curvePoints.add( 20, 0, 0 )

const nurbsCurve = rhino.NurbsCurve.create( false, 3, curvePoints )

//this is what you should send to compute
const curveDataToCompute = JSON.stringify( nurbsCurve.encode() )
console.log( curveDataToCompute )

Thanks for advice! But… I think I’m close, but still Rhino Compute is throwing an error

Data which I’m sending to Rhino:

Can you provide example code and definition to test? Also, how are you running compute?

This is a more complete example that is working for me:

Unfortunately I cannot show the definition file… but it turns out that your solution works! The problem is when I want to use the same code in a solution based on compute.appserver. So I will look for discrepancies in the coming days. Additionally, I had a problem on the Rhino Compute side, where I got an error:

Ok. It would have been good to know how you were calling compute. For appserver it would be similar:

Note: the is in /src/files

Hi Luis!

Your responses have been very helpful! Thanks.
Could you kindly advise on how to send an entire Rhino document to the evaluate definition?
In the image below, I hope to send a rhino document to the “RH_IN:rhinoFile” node.

The samples on Github first parses through the objects, and then sends extracted data to definition. I prefer to control this logic in Grasshopper instead.
My current setback is that the “RH_IN:rhinoFile” node is unable to accept the document that I’m feeding it. I’ve tried encoding and JSON.stringify() the rhino document, but I am still unsuccessful. You may reference my 2 failed attempts below.

How do I send a grasshopper definition an entire rhino model as input?

Thanks in advance,

Have you seen this post?
You can probably read a rhino3dm file in a similar way with a headless document


Thanks Martin Borst! This might actually work. Thanks for forwarding this to me. Cheers!