Are generic data types allowed when using EvaluateDefinition() function of Rhino Compute?
I’ve successfully tested the feature using the code sample (which included a curve and number input type). But trying to use data trees result in the following error:
{'statusCode': 500, 'message': 'Something went horribly, horribly wrong while servicing your request.', 'details': 'Nancy.RequestExecutionException: Oh noes! ---> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index\r\n at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)\r\n at compute.geometry.ResthopperEndpointsModule.Grasshopper(NancyContext ctx) in C:\\src\\compute.geometry\\ResthopperEndpoints.cs:line 474\r\n at Nancy.Routing.Route.<>c__DisplayClass4.<Wrap>b__3(Object parameters, CancellationToken context)\r\n --- End of inner exception stack trace ---\r\n at Nancy.NancyEngine.InvokeOnErrorHook(NancyContext context, ErrorPipeline pipeline, Exception ex)'}
Here’s my code:
import compute_rhino3d.Util
import compute_rhino3d.Grasshopper as gh
import rhino3dm
import json
import os
compute_rhino3d.Util.url = 'http://123.456.789.000:8000/'
pt1 = rhino3dm.Point3d(0, 0, 0)
circle = rhino3dm.Circle(pt1, 5)
# convert circle to curve and stringify
curve = json.dumps(circle.ToNurbsCurve().Encode())
# create list of input trees
tree = gh.DataTree("RH_IN:tree")
tree.Append([0], [curve])
tree.Append([1], [10])
trees = [tree]
gh_path = './test.ghx'
output = gh.EvaluateDefinition(gh_path, trees)
print(output)
Any ideas?
Here’s a screen shot of my simple gh definition.
Hi, Morteza:
I tried the code you provided and didn’t change anywhere except the authToken. However, there was an error. I would be appreciate it if you could helps to check what’s wrong with it. Thank you very much!
this is the code below:
import compute_rhino3d.Util
import compute_rhino3d.Grasshopper as gh
import rhino3dm
import json
import os
compute_rhino3d.Util.authToken = MYTOKEN
pt1 = rhino3dm.Point3d(0, 0, 0)
circle = rhino3dm.Circle(pt1, 5)
# convert circle to curve and stringify
curve = json.dumps(circle.ToNurbsCurve().Encode())
# create list of input trees
tree = gh.DataTree("RH_IN:tree")
tree.Append([0], [curve])
tree.Append([1], [10])
trees = [tree]
gh_path = './test.ghx'
output = gh.EvaluateDefinition(gh_path, trees)
print(output)
This is the error message:
{‘statusCode’: 500, ‘message’: ‘Something went horribly, horribly wrong while servicing your request.’, ‘details’: ‘Nancy.RequestExecutionException: Oh noes! —> System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.\r\n at System.Xml.XmlTextReaderImpl.Throw(Exception e)\r\n at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()\r\n at System.Xml.XmlTextReaderImpl.ParseDocumentContent()\r\n at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)\r\n at System.Xml.XmlDocument.Load(XmlReader reader)\r\n at System.Xml.XmlDocument.LoadXml(String xml)\r\n at GH_IO.Serialization.GH_Archive.Deserialize_Xml(String xmlContent)\r\n at compute.geometry.GrasshopperDefinition.ArchiveFromBase64String(String blob) in C:\src\compute.geometry\GrasshopperDefinition.cs:line 660\r\n at compute.geometry.ResthopperEndpointsModule.Grasshopper(NancyContext ctx) in C:\src\compute.geometry\ResthopperEndpoints.cs:line 69\r\n at Nancy.Routing.Route.<>c__DisplayClass4.b__3(Object parameters, CancellationToken context)\r\n — End of inner exception stack trace —\r\n at Nancy.NancyEngine.InvokeOnErrorHook(NancyContext context, ErrorPipeline pipeline, Exception ex)’}