Losing data between GHPython components

Hello,

I’m trying to output a nested python list into another GHPython components.

I’m using two components because in the future I wish to use them at different times, and also one has to calculate a lot more than the others.

I’m trying to output “path_point” which is a list of lists of coordinates. As you see it outputs these IronPython.Runtime.List, I know that grasshopper can not read list of lists bur for right now I only want to to input it in others GHPython components.

As you see, I’m losing almost one third of the data.

In “x”, I changed it to list access and the Type hint nothing seems to coincide with Python lists.


With another sets of list, and checking the len() of every list, it changes every time:
bug2

If need to, I can share the code, but for right now I don’t feel like the problem lies in the rest of the code, as the console of the output show exactly what I wish to have in the input.

I’m using Grasshopper 1.0.0007 in Rhino 6

Best regards, :slight_smile:

Hi,
Are you creating and modifying a copy of the list anywhere? Are you aware of the unexpected behaviours you can get when modifying copied lists in Python?

its pretty simple:

treeConvert.gh (6.5 KB)

Edit: As an alternative you can create a Grasshopper.DataTree[System.Object] and store data with the right path (Grasshopper.Kernel.Data.GH_Path) instance directly. Without understanding C# this might be difficult to do.

Hey,

so I wasn’t not aware of the problem that you can have with copying and modifying a list, but in this case, I’m never creating copies of list. In this code I’m not deleting or changing elements in list or dictionaries, only adding elements to list/dictionaries and sometimes resetting them.

Right now I’m not trying to output back to grasshopper, just to properly read the input of the first Python component.

well what about wrapping it?

wrapping.gh (6.9 KB)

3 Likes

Yes, enumerables like list are special objects in GhPython, because the component has to make guesses: do you mean to output a single item or you want to output a Grasshopper list? Because of how Grasshopper works, nested lists will behave as lists of data in the component that is immediately following the current one. You can still import them as data, or possibly with the List access value. Grasshopper has the DataTree type for lists of lists. You can’s easily outsmart this setup if you pass through normal Grasshopper wires, because it’s just how Grasshopper works.

The only simple way to deal with it, is via the ghcomplib.treehelpers functions. They automatically transform arbitrarily nested lists of lists in corresponding DataTrees.

If your goal is to pass special data, then possibly wrapping it is also a solution.

1 Like

yes. I find it quite useful to do wrapping in (Iron-)Python. In C# you can’t simply do this, due to its strongly typed character. The only working way in C# would be using a Tuple<T,…> class, since a class definitions created in a script context are not passable (At least without any weird hacks or reflection mechanism). Python just doesn’t need that info. Perfect simple. As said I wouldn’t mess with Datatree without knowing GH/C#, but I find ghcomplib.treehelpers interesting. Didn’t know about them.I’ll try that.

Edit: works like a charm, cool :slight_smile:

wrapping_and_treehelper.gh (8.5 KB)

Thank you @TomTom and @piac for the wrapping solution !
I didn’t that know that Grasshopper wires were more complex than they seem, I will look more into the treehelpers and wrapping class. My teacher also just told me about the tuple bodge. :slight_smile:

Best regards !