Compute-rhino3d read gh file error

Hello,
I have a problem to read gh script component. I used this code block.

# convert breps and points
# create list of input trees
right_tree = gh.DataTree("RH_IN:Right Surface")
right_tree.Append([0], [right[0].Geometry])
 
left_tree = gh.DataTree("RH_IN:Left Surface")
left_tree.Append([0], [left[0].Geometry])
 
points_tree = gh.DataTree("RH_IN:Pt")
points_tree.Append([0], [density_points[0].Geometry, density_points[1].Geometry, density_points[2].Geometry])
 
trees = [right_tree, left_tree, points_tree]
output = gh.EvaluateDefinition('2021_03_11_Brace_Generation_Script_4.gh', trees)
print(output)

2021_03_11_Brace_Generation_Script_4.gh (4.7 KB)

I’ve got this error.
{‘statusCode’: 500, ‘message’: ‘Something went horribly, horribly wrong while servicing your request.’, ‘details’: “Nancy.RequestExecutionException: Oh noes! —> Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: {. Path ‘values[0].InnerTree.0[0].data’, line 1, position 645984.\r\n at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)\r\n at Newtonsoft.Json.JsonTextReader.ReadAsString()\r\n at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateDictionary(IDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, JsonProperty containerProperty, String id)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)\r\n at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)\r\n at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)\r\n at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)\r\n at compute.geometry.ResthopperEndpointsModule.Grasshopper(NancyContext ctx) in C:\src\compute.geometry\ResthopperEndpoints.cs:line 66\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)”}

It doesn’t look like the definition got attached to your post.

Sorry, I’ve attached the grasshopper file again.

You need to define inputs and outputs for your definition that you plan to call remotely. I would recommend installing Hops and testing your definitions with that to ensure everything will work before trying to call the definition from python.

For inputs, use the “Get” components in Grasshopper:

  • Get String
  • Get Integer
  • Get Point
  • Get Number
  • Get Geometry

For outputs, you want to group a param and name it RH_OUT:{name}, where {name} if the name of the output you want compute to return. Here’s a sample that uses inputs and outputs
https://github.com/mcneel/compute.rhino3d/raw/master/src/hops/definitions/SpikeyThing.gh

Hi @stevebaer,

I am trying to load my GH file with compute.rhino3d for python. I have followed the following video for the same

I have a geometry component in my script which allows for loading geometry. I have used GET Geometry component from hops as suggested in this post.

The main problem I am facing now is to call the geometry component into the python file. Can you post here an example which explains how to call this component in python? Or suggest a way to do so?

I am getting this message in my compute server window:

System.FormatException: Invalid length for a Base-64 char array or string. at System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength) at System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength) at System.Convert.FromBase64String(String s) at compute.geometry.GrasshopperDefinition.ArchiveFromBase64String(String blob) in C:\projects\compute-rhino3d\src\compute.geometry\GrasshopperDefinition.cs:line 983 at compute.geometry.GrasshopperDefinition.FromBase64String(String data, Boolean cache) in C:\projects\compute-rhino3d\src\compute.geometry\GrasshopperDefinition.cs:line 107 at compute.geometry.ResthopperEndpointsModule.GrasshopperSolveHelper(Schema input, String body, Stopwatch stopwatch) in C:\projects\compute-rhino3d\src\compute.geometry\ResthopperEndpoints.cs:line 66 at compute.geometry.ResthopperEndpointsModule.Grasshopper(NancyContext ctx) in C:\projects\compute-rhino3d\src\compute.geometry\ResthopperEndpoints.cs:line 135 at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at Nancy.Routing.Route.<>c__DisplayClass4.b__3(Object parameters, CancellationToken context) ::1 - [2021-08-11T12:13:34.7657911+02:00] “POST /Grasshopper HTTP/1.1” 500 -

Can you please post a sample gh definition which shows this issue as well as the code you use that shows what you are passing as input to the gh solve endpoint?

Slicer.gh (31.5 KB)

Hi @fraguada & @stevebaer ,

Attatched herewith is the GH definition and below is the Python code:
Slicer.py (4.4 KB)

Let me know if you come across any workaround forthe same.

What kind of geometry are you trying to feed into “InputGeomertry”? I’m trying to figure out how to use your slicer.gh definition.

Hi @stevebaer,

You can import any geometry from a 3DM file loaded in RHINO and then “set as one geometry” in the the grasshopper definition in the “InputGeometry” component. After which the script runs and slices the geometry which is the required output.

Can you send me geometry that works? When I tried with a sphere I got several errors and no output

Test.3dm (109.2 KB)

Here is a test geometry that should work. I have used some plugins which should be the main reason for the definition ot working but I guess that GH should give some errors and ask you to install those plugins at the start.

Let me know if it works.

Hi @stevebaer,

Any update on the solution for this issue?

Am I supposed to still get errors with the test.3dm model that you posted?

The relays were causing an issue with setting up default values in Hops which I am in the process of fixing now.

I’m testing with Hops since I know that once we have this working with Hops we can get it to work with python or C#

Hi @stevebaer,

The errors should be fine. It’s basically a provision for the input geometry consisting of a different set of characteristics.

Interesting, thanks for the update. I will try the same on my side as well and let you know if I have any update.

Thanks for the efforts. Much appreciated!

You shouldn’t have to remove the relays.

A new version of Hops (0.8.0) is now available on the package manager that should fix this issue.

So does that mean it can now work with python or C# as you suggested last time around?

Slicer.gh (30.4 KB)
I had to remove the referenced input geometry parameter from the slicer.gh definition to get this to work (see attached). I’m still trying to figure out how to properly solve that issue.

If you use hops and reference slicer.gh as well as pass in your test.3dm geometry for the geometry input, you should get good results. Once you have that working, right click on the hops component and choose “export python sample…” This will create a basic python sample that makes a call to slicer.gh with some sample input data. I’m hoping this will help you compare with your python script to help figure things out.

Update: I was mistaken. Your initial slicer.gh works fine with Hops. I get an error as that definition has a geometry reference, but that is reference isn’t really needed and the proper output is generated.