Group Branch Items Together in a New Data Tree

Hello All,

I’m trying to group a list of item from a separate branches. The list of items is in the above panel where I’ve already removed the items, and the pattern for grouping is in the lower list, 0 signifies a new group or in data tree terms, a new branch and I’d like all the corresponding branches shown in the above list and illustrated in the pattern with a 1, to be combined in a single branch. So the end result for what you see here is:

{0}
0 Table
{1}
0 Plant Type
1 Common Name
2 Botanical Name
3 Description
{2}
0 Origin
1 Vigour

I vaguely remember doing something like this in a tutorial but it may have been over a year ago. I’ve tried all the standard resources we learn from and not found a solution.

Thank you!

Scott

I went through all the tutorials I remember and dug through all the nodes I could find for dealing the Data Trees and I’m still clueless.

@scottyvalentine If I understand correctly, you can extract each item per group and combine them to your liking. You can use “list item” to get the item from the red group and “Sublist” for items in the blue and purple groups, then use "entwine” for each group. If you attach the GH file I can take a crack at it.

Thanks for having a look at this @noambdr

The data will be dynamic, so the list of items in a group may grow or shrink. I’m certain there needs to be some kind of condition added that says IF item = “” then new list. but because of my level of understanding in GH and programming, I can’t work out how to express that.

I’ll play around with the nodes you recommended and see what I can do.

Conditional Data Tree Branch Groups.gh (14.4 KB)

it seems to me that the logic you’re after is that every time there’s a 0, it creates a branch, and a 1 inserts items in that branch (read caveat below)
Conditional Data Tree Branch Groups[custom py].gh (18.3 KB)

so this python script should do it

import ghpythonlib.treehelpers as th
tree = []

temp = []
counter = 0
for i in y:
    if i == 0:
        if len(temp)>0:
            tree.append(temp)
        temp = []
    else:
        temp.append(x[counter])
        counter +=1
if len(temp)>0:
    tree.append(temp)

a = th.list_to_tree(tree)

caveat: this logic leaves some of the items in the first list unadded. why? because 0 creates a branch and 1 adds the item to that branch. you need as many 0s as there are branches, and as many 1s as there are items. currently you have 12 items but only 9 1s

You are right, that’s exactly what I was looking to do. I’ll have a play with that but I don’t understand your caveat.

The data is from an excel spreadsheet so the 0 is Group these items exist within, within excel that column is left blank. So you have Groups (0) on Row A in excel, and then parameters (strrings) on Row B and then parameters following that.

First time trying to drive revit family models from a spreadsheet, this is one small part of it. I’m sure I’ll have alot more questions as I go through the process.

oh, sorry, i missed the fact that the item list had missing branches
i just saw the 12 and thought it had 12 items


but in regality you have 9 items.

so there is no caveat - my bad

there are more elegant py scripts to deal with excel files, but i guess the gh file i posted above works for now. if you find that you need another data structure than above, reach out

1 Like

So this is perfect.

Groups and Parameters sit at the same list level now.

Happy Days… I just wish I understood properly how to code more than hello world.

Lets see if I can learn from this is and extract the parameter values now.

Thanks you so very much @adel.albloushi

1 Like

Sorry to keep bothering you @adel.albloushi , when I open this file in Rhino.Inside firstly it appears with a different looking script editor and secondly it doesn’t work at all, if I try type in the script editor it says “Cannot edit in read-only editor”

Is there a enable button I need to press somewhere?

@Japhy maybe this is your area in RIR?

I just noticed this runtime error.

This c# groups consecutive paths
SharedScreenshot
Conditional Data Tree Branch Groups.gh (9.4 KB)

1 Like

Wow thank you @ThomasE

You can achieve this goal without coding knowledge or any 3rd party plugins. Here is a solution with just Grasshopper vanilla components.


GH Vanilla Components Only-Branch Groups.gh (8.2 KB)

1 Like

Hey @Danial_Keramat that’s great. Relative Difference is once I haven’t used before and I don’t yet think my skill level is up to being able to solve this sequence of nodes. Slowly growing my understanding. I’ll test this out.

Thank you very much.

1 Like