Hi all,
I am writing a simple script that takes a tree, and returns false if any of the items inside the list is false.
The script is working with my test list #test = [[False, True,True], [True, True,True], [True, True,False]]
the result being: [False], [True], [False]
But its not working the same way with my data from GH.
What am I missing?
Below is the script and the two screenshots showing the results I get from my test vs. my data from GH.
import clr
clr.AddReference("Grasshopper")
from Grasshopper import DataTree
from Grasshopper.Kernel.Data import GH_Path
def check_collection(tree):
all_true = True
for path in tree.Paths:
branch = tree.Branch(path)
if not all(branch):
all_true = False
break
if all_true:
return "Collection is true"
else:
return "Collection has at least one or more false"
# Test data
test_tree = DataTree[bool]()
test_tree.AddRange([True, True, True], GH_Path(0))
test_tree.AddRange([True, True, True], GH_Path(1))
test_tree.AddRange([True, True, False], GH_Path(2))
output = check_collection(test_tree)
print(output)
This should correctly identify if there’s any false element in the datatree
Hope this helps,
Farouk
Hi @farouk.serragedine !
Your script indeed identifies if there is a false in the list.
However, I wish to have as output the tree structure shown in the second image (a branch per each resulting boolean).
Do you have any suggestions?