Iteratively Splitting Tree Branches

I have a 3d matrix of points that I am using to make polylines. Some of these branches need to be modified, but working with data trees can get complicated quite quickly. Because of the way that the points were made, some points end up in a list together that shouldn’t be together. My plan is to iteratively go through the branches, and iteratively go through the points in each branch, to measure the distance to their neighbors (based on index) and see if they are too far apart from eachother to sensibly be in the same list.

The end goal is to have each branch be its own independent polyline. Each polyline should not intersect a polyline from another branch. Which, I guess maybe I could just flatten all the data, then find any intersection points, and try to cull out lines. But this would also be complicated b/c the part of line needing to be culled would vary where it occurs. I also would like to get better at working with data trees.
lines bw curves03.gh (258.4 KB)

This is an example of a properly split tree branch(only achievable because I used the TreeBranch component to select 1 branch, then iterate through it as a list)

However, I haven’t been able to use the DataTree class effectively in Python. I tried first, iterating through branches, then through the lists, and trying to export indexes of half the list to be used in a TreeSplit mask. I couldn’t get this to work.

Of course, as stated previously, I can split an individual list if I first isolate it with the TreeBranch component:

RELATED (DUPLICATE?) THREAD:

@Joseph_Oster , this is building on the same grasshopper file. However, this is a completely new issue I am dealing with.

Now I am dealing with splitting lists, and the lists are not simple. Branch - Branch - list. And the list at the end of the hierarchy needs to be split based on Point3d proximity

I can see that. Just saying…

How about taking the resulting overlapping polylines, exploding them, and culling the lines over a certain length? Afterward, you can join them back up again. This way you don’t have to worry about messy branch coding like you are describing.

yes! This absolutely works, and is way simpler than what I am describing.

I guess the general question is just how to iterate through branches. It looks like there are methods to turn a datatree into a list of lists, modify it, then recombine using the orginal path indices. I was just wondering if anyone knew how to more precisely modify the branch structure. But maybe I save that for another day.

I assume you have seen this, but just in case I’ll post it here.

As far as I understand, you turn the data trees into python list objects, and then when you’re finished you can turn those lists (or lists of lists, or lists of lists of lists, etc.) back into branch structures. In this case, if you format the data into python lists how you want them to work as Gh datatrees, then when you ‘convert’ the lists back to datatrees, they will keep that same structure. You can see here that there is formatting that goes into the conversion process:

layerTree = th.list_to_tree(layerTree, source=[0,0])

Nevertheless, my two cents, I always try to stick to simple, native methods until the very last moment and then add in python to do the things that native Gh component absolutely can’t.