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.
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.
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.
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.
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.
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.