I have one list with many path
I want to merge all the path who have the last number in common with the first number of an other list
here is what I want to do (highligthed in blue)
C# script.
This is a “directly translated” algorithm, as like as doing it manually.
It can’t work if you have empty branches or your tree structure is not consecutive.
(ex {0},{1},{2},{4},{5} … missing {3})
private void RunScript(DataTree<int> x, bool y, bool z, ref object A)
{
int branches = x.BranchCount;
Grasshopper.DataTree<int> tree = new Grasshopper.DataTree<int>();
tree.AddRange(x.Branch(0), x.Path(0));
bool found;
for (int i = 1;i < x.BranchCount;i++){ // Starting from second branch as first is already passed
found = false;
for (int j = 0;j < tree.BranchCount;j++){
int a = x.Branch(i)[0]; // First item of branch "i" of original x tree
int b = tree.Branch(j)[tree.Branch(j).Count - 1]; // Last item of branch "j" of tree that is building up
if (a == b){
if (y){ // Removing consecutive duplicate by removing last item of current "j" branch
tree.Branch(j).RemoveAt(tree.Branch(j).Count - 1); }
tree.AddRange(x.Branch(i), new Grasshopper.Kernel.Data.GH_Path(j));
found = true; // Found a branch in tree where to add x{i}
if (z){ break;} // Exiting current for cycle if z=true
}
}
if (!found){
tree.AddRange(x.Branch(i), new Grasshopper.Kernel.Data.GH_Path(tree.BranchCount));
}
}
A = tree;
}
hi guys, thanks for your help, but it appear that your suggestion doesn’t work perfectly when I merge it on my grasshopper with the different files I’am working on and I don’t understan really why…
I did try to simplify my own work to turn it easier to work on…
so i’am no able to have only 2 value to work on on my tree…
hope it help you to help me…
basicly I want the code to go on and on as long as there common value in the list
when I repeat Riccardo’s tool 4/5 or 6 time I get the final result I want, the problem is that depending the file I ope, I don’t kno how many time I have to repeat the same code, so I want it to do it by itself…
Hs-Kim tool do a good work too, but it did creating many times the same list, so I would like the repeated list to be delete.
Please don’t do this, you should really work with smaller/simpler definitions. This could and will go against you.
Clean your code, optimize, make clusters.
Also I didn’t have like 10 of your plugins, so everything is without data for me…
What you need to do?
Reiterate in the list until it doesn’t “shrink” anymore?
““Reiterate in the list until it doesn’t “shrink” anymore?”” -> Yes
Riccardo, I know that I shouldn’t use many time your C++ tool connected together, but I did try because it appear that your code do not seem to always restart from the top.
But I don’t do C++ code so I don’t know how to modify it…
here is a file with some more explanation and example, I know that my question is hard to explain but in fact I think it’s a simple one for tough grasshopper guys as you seems to be.
If you want to always set “true” the loop from start thing, remove the z input param and edit code and add a line:
bool z = true;
at the start of the script, just under “private void RunScript”…
And if you need more looping, increase value of “maxloops” inside the code…