Evaluate grasshopper definitions with RhinoCompute.Grasshopper.evaluateDefinition()
Works with both .gh and .ghx files in node.js and in the browser
Construct inputs with the RhinoCompute.Grasshopper.DataTree class
Node.js example
compute = require('./compute.rhino3d.js')
fs = require('fs')
compute.url = 'https://staging.compute.rhino3d.com/'
compute.authToken = 'Bearer' + process.env.RHINO_COMPUTE_TOKEN
var buffer = fs.readFileSync('leland.gh')
var definition = new Uint8Array(buffer) // works for both .gh and .ghx
var tree = new compute.Grasshopper.DataTree('RH_IN:106:0001')
tree.append([0], ['Lorem ipsum dolor sit amet'])
compute.Grasshopper.evaluateDefinition(definition, [tree]).then(res => {
console.log(JSON.stringify(res))
}).catch(err => {
throw err
})
Browser example
<html>
<head>
<script src="compute.rhino3d.js"></script>
<script>
RhinoCompute.url = 'https://staging.compute.rhino3d.com/'
RhinoCompute.authToken = RhinoCompute.getAuthToken()
var tree = new RhinoCompute.Grasshopper.DataTree('RH_IN:106:0001')
tree.append([0], ['Lorem ipsum dolor sit amet'])
var trees = [tree]
fetch('leland.gh')
// .gh
.then(response => response.arrayBuffer())
.then(buffer => new Uint8Array(buffer))
// .ghx
// .then(response => response.text())
.then(definition => RhinoCompute.Grasshopper.evaluateDefinition(definition, [tree]))
.then(res => console.log(JSON.stringify(res)))
.catch(err => { throw err })
</script>
</head>
</html>
RhinoCompute.Grasshopper.evaluateDefinition()
RhinoCompute.Grasshopper.DataTree
classNode.js example
Browser example
Example Grasshopper defintion – leland.gh.zip