KeyError in developer samples "twisty"

Hi people

I want to use Rhino compute for my parameter study and I wanted to look at examples. I found https://www.youtube.com/watch?v=GCB7duijXQQ but I saw in this forum that the code there is outdated. In Github, I found https://github.com/mcneel/rhino-developer-samples/blob/7/compute/py/SampleGhBasic/lines.py. I let run the exact same code in my Pycharm, but got the following error:

Traceback (most recent call last):
File “C:/Users/User/Desktop/Masterarbeit/Rhino Compute/twisty.py”, line 27, in
branch = output[‘values’][0][‘InnerTree’][‘{ 0; }’]
KeyError: ‘{ 0; }’

This references line 27: branch = output[‘values’][0][‘InnerTree’][‘{ 0; }’]

I am also curious how to work with two separate geometric outputs (points and meshes). Can someone give me a hint on this? :slight_smile:

Kind regards and thanks in advance!

Oskar

did you come to any conclusion on this? I’m having some errors with newtonsoft.json and the ResthopperEndpointsModule.Grasshopper on my personal project. So I went to test this py example and I get the above error. I must be missing something. At least I am seeing the responses in the rhino.compute window locally.

Maybe the data structure changed? You should interrogate what is in the output object.

1 Like

I can’t get it to work either. I don’t think the inputs RH_IN: are receiving any data which is where the problem might be. If given a default value, they take the default value and the script isn’t changing them.

Made my own simple test where also the inputs do not seem to be receiving data.

python --version = 3.10.11
rhino = 7.32.23221.10241.2023-08-09

@fraguada inputs work for me using an int component grouped with name RH_IN:integer but not if I use the getInteger component and name it integer.

I have Hops v.0.16.0

1 Like

As I suggested, the data structure had indeed changed:

from
branch = output[‘values’][0][‘InnerTree’][‘{ 0; }’]
to
branch = output['values'][0]['InnerTree']['{0;0}']

Writing 10 lines to twisty.3dm

1 Like

I tried your script and gh def, as is, and switching to context bake and everything works as expected. I switched from “linear” and “courtyard” and got different kinds of points.

I am not sure which version of the compute server I am using since this isn’t a machine I set up and for some reason I cannot hit the /version end point, but will report back on that.

The Rhino.Compute server version:
{"rhino":"7.27.23032.13001","compute":"1.0.0.0","git_sha":"25466b44"}

1 Like

yes, the data structure part was understood,

the point is that the contextual inputs don’t work,
the container in a group properly named does work.

why don’t the new contextual inputs work with python and compute?

1 Like

They work fine. I tested it without issue in @mcbennett’s definition and a modified twisty:

twisty.3dm is corrupt for some reason, but that is another problem. I’ll look into it.

1 Like

odd, they do not work on our ends. :frowning:
thanks for looking into it, sticking with the grouped containers, as we know they work.

I see you are on a macbook pro, maybe it is a windows problem?

1 Like