top of page
Search
  • Writer's pictureWill

IronPython.Runtime.List back to DataTree FAST!


Let us get straight to the point. The problem is when you script a list of lists data structure in the GHPython component the output doesn’t recognize the structure as a tree as you’d like. The quick solution that I found is by passing everything through an empty C# component. See screenshot below.


If you’d like to know more, read on.

To demonstrate this common problem, I use a small example I ran across at work the other day. One of my colleagues was trying to isolate contour curves on different elevations. She wanted to group them into branches of a tree and came to me for help. These curves come in jumbled. Ones on the same elevation need to be in the same branch.

Grouping them into branches of a tree gives the benefit of batch actions on curves of the same level. For instance, after grouping, you can use the loft component and it would only loft all the curves in the same branch.

In the heat of the moment, I suggested using custom scripting in python because it’s much more straightforward and I am better at data structure manipulation by python than by native GH components. So here is the script and a screenshot of a bunch of random curves on different levels. The jitter component is to make sure there isn't an order to the curves for demo purposes.



Concisely, line 3 initiate a list. Variable ‘uniq’ is essentially a set, keeping only unique items. Parameter ‘zs’ is all the Z values of the curves’ starting points. By using ‘set(zs)’, ‘uniq’ now holds only unique Z values, i.e. the levels/elevations. The nested for-loops goes through each elevation and look for curves that are on it. It puts ones on the same level in a list and append this list to the overall list. In the end, variable ‘L’ is a list of lists. You can see in first screenshot that the output 'a' is this strange data type IronPython.Runtime.List that none of the GH component can use.

A quick Google search can point us to a few blogs/websites that explain how we can turn these into a legitimate data tree of GH. For example, visit here. These are great ways to understand the script mechanisms but I never manage to remember those codes. Each time I run into a similar problem, if I don’t have internet at my finger tip I’m toast!

Luckily I found a trick. Simply push this list of lists into a C# GH component. Pass it in whole to the output of C# like shown below. Voila!


Recent Posts

See All

How to pass all ARE exams

Now that I’ve finished all my ARE exams and registered as an architect, I can summarize a few pointers for anyone still in pursuit. These are things that I found to be noticeably helpful along my way

ARE 5 and prep materials

Here is an update on my progress on ARE 5 exams and my experiences with the preparation materials on the market. Ever since I passed my three managerial exams (PjM, PcM, CE), I've taken a long hiatus

GhPy can multi-thread too! But wait...

GhPy component is known to be a bit slow in its performance because of the JIT compiler it utilizes. However, GhPy is a powerful widget to test out scripting logic without the baggage associated with

bottom of page