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