InnerTree structure in response JSON from rhino.compute

Hello everyone!

I have encountered a strange issue in the handling of the response Json from rhino compute. I have a script where I return multiple values;

  • a draco compressed mesh is passed out as RH_OUT:Mesh
  • an array of rhino curves are passed out as RH_OUT:Curves
  • a double is passed out as RH_OUT:Value.

I start by making a json from the response

const responseJson = await response.json()

and then I have a method that parses the return json into the different objects that it contains. Here is a simplified version:

rawAlternative.data.values.map((value, i) => {  
        const { ParamName, InnerTree } = value
                if (ParamName == 'RH_OUT:Mesh') {
                      const meshString = JSON.parse(InnerTree['{0}'][0].data)
                      alternative.meshString = meshString } 

                else if (ParamName == 'RH_OUT:Curves') {
                      alternative.curves = InnerTree['{0;0}'] }
               }
            
               return alternative
         }

Ok, so the problem that I’m having is that the mesh on the InnerTree sometimes appears on ‘{0}’ and sometimes on ‘{0;0}’ and I can’t figure out why this is. I understand that it has to do with grasshoppers way of handling datatrees, but I flatten everything before I pass it out with the RH_OUT: parameters so I don’t know why it is inconsistent. I always just output a single mesh in the RH_OUT: parameter.

Do you have any suggestions on this or know how rhino creates the InnerTree object from the RH_OUT: parameters? :slight_smile:

Thanks!
BR
Erik

Hey Erik, this might be late but the “flatten” component doesn’t work the same way on linear trees that it does on branched trees.
You can use the “Suirify” component to ensure your data is flattened the way you decribe it.

See also these threads here for example:

Hello Headblast!

Thank you for this. This particular problem is solved, but we’re still working on the project so all tips ate much appreciated!

BR
Erik