Data Tree Matching in ghPython -- Trees of Differing Depths

I’ve made a function in Python that makes a negative curve parameter “wrap” the curve (so, basically, if t is negative, subtract t from max of curve domain).

For context, I have a working knowledge of Python, but I’m not very experienced, and this is my first attempt at using the Grasshopper library in Python. (I’m also open to solutions using C# if it would be better suited to solving my issue)

The Python script works just fine with item access when the input is a single curve with a number of curve parameter inputs, or with multiple curves when the lists of curves and parameters are made to align before going into the python component.

I’m struggling to get the function to work with tree access for the tree structure I would like to be able to input and would appreciate any help / advice / examples that may be helpful.

Here is my goal data matching, with the colored x’s being items, the left side being the input curves and the right being the parameter values:

The GH definition I’m working in is using this python component to cull points from a curve when they result in an angle that doesn’t meet a set tolerance – the file has three iterations inside it:

The first is taking in one curve and a basic tree of parameters, using item access, getting a working result.

The second is taking in a grafted list of curves, and a more complex tree of parameters, using item access the data does not match in Python as intended.

The third uses a workaround in GH that duplicates data in the list of curves to match the list of parameters before going into Python, so that the Python script will work with item access. This is working fine for what I need it to do, but it would be great to figure out how to solve this problem in Python.

I’ve also left in my attempt at getting the script to work with tree access. It makes sense in my head but I’ve hit a point where I’m struggling to make sense of the errors I’m getting and some alternative opinions could really help.



Can you please clearly explain what you are trying to solve computationally? You have a list of closed polylines, and what would you like to do with them? Also ignore all the data tree things for now.

What kind of data do you want to get from the parameters? Also it’s always a good idea to have the parameters be in a domain from 0-1 to easily manage the number space. Instead of having curves / lines with parameter domain from a-q

If you describe your problem explicitly I could probably write what you need in a c# component

Thanks for the reply,

The curves represent the outer boundary of unfolded plate metal shapes (the actual geometry I included are not the real boundaries, just nonsense curves that I can share more freely).

I’m taking parameters on the curve at both directions from each discontinuity, then returning a boolean pattern to identify any discontinuity that creates an angle that doesn’t pass a certain threshold (this is used to determine sections of the curve which require a certain operation during fabrication).

I’m not reparameterizing the curves simply because in its intended use, the curves will be coming from a larger definition/workflow and I’ve been asked to maintain the input curve domains (I’m working on this with / for a co-worker).

Ok So basically,

for each unfolded plate, take all curves which are its subset and calculate the angle between each of them. If one of the angles is less than the aloud tolerance, then it should be revised. Is this correct?

What is your threshold?

The angle tolerance should be 175 degrees – for any angles above this, the curves are going to be joined, while all other curves will be dis-joined.

That said, the key part here that we need the component to handle is returning the list of points in the same structure which the parameter values are being input

175 degrees in interior or exterior angles? For example if you have an interior angle that is 113 degrees the exterior part will be 247 degrees, so it wont meet the criteria there.

We are always using the smaller angle between each set of vectors (arccosine of the dot product). So effectively, we are looking for any angles between 175 and 180 degrees

Yeah the angles in degrees that the dot product returns are always between 0 and 180. Ok great. So I will handle everything in 1 C# script, My output will be a data tree containing all segments, joined or not and each branch will correspond to every metal shape.

Just a heads up… I will not check if curve segments of each metal shape will be in order though, so if there is no guarantee of this in the input, that is something you guys can write on your own :wink:

I will post something tomorrow, over here is near bedtime.

Thanks! I really appreciate your help and time. Looking forward to seeing what you come up with. I don’t believe we will need an ordered list, but thanks for the heads up

Ok I gave it a quick try,

My algorithm is mostly working, when joining corresponding lines together except in 2 conditions ( but the code does not break)

  1. When A = B - 3
    A : Total of angles above threshold
    B: Total number of curves that make up a metal sheet.

The algorithm will return one polyline and one line-like curve. Instead of two polylines and one line-like curve

  1. When A = B - 2
    A : Total of angles above threshold
    B: Total number of curves that make up a metal sheet.

    The algorithm will return one polyline, Instead of two polylines.

Also, all angles above the threshold are marked with a thick pink line.

Anyways, I don’t have much time now too keep improving it, but I can look back at it later if need be. (12.8 KB)

This is great, thank you!

At a first glance it seems to be doing everything we need very efficiently. I’m out of the office so I can’t check with the folks who would be using it, but if it needs to be tweaked at all, I think we should be able to handle it on our end.