I want to make a loop over every item in a branch in a tree, With C#, how do I do that?
Get the branch you want, then foreach your way over it like you would with a List or Array.
But how do I get a branch from a tree?
and how do I refere to that branch in the foreach?
since I want to og through every branch in the tree, and every item in the branch
Top of my head (and depending on whether you’re dealing with DataTree<T>
or GH_Structure<T>
) something like this:
var tree = ...;
for (int p = 0; p < tree.PathCount; p++)
{
var path = tree.Path(p);
var list = tree.Branch(p);
for (int i = 0; i < list.Count; i++)
{
var item = list[i];
...
}
}
thanku sooo much
! it is starting to work!One problem…
It is Three branches in the Three, and the output gives the centernode for one of the branches Three times, instead of giving the centernode for each branch…
You are assignin B from inside the loop, so it gets overwritten every time. That’s probably a bug.
Do you really need to operate on the whole tree though? Wouldn’t it be enough to set the input access to List instead of Tree and leave out the outer loop of your script?
Do not understand what you mean? I am suppose to apply a joint geometry later to each intersection, so I need the centerode for each intersection to apply it! Now I can do it for you each single, but I want to apply it to the whole structure! Could I send you the whole GH file? This is so helpful, very very nice of you!!
Globalstruc_Rhino.3dm (32.7 KB)
Global_structure_intersection2.gh (91.7 KB)
More on…C# for loop