public void ChangePath<T> (ref DataTree<T> tree, int dim){ // dim for dimension position
DataTree<T> tmp = new DataTree<T>();
foreach(GH_Path path in tree.Paths){
if(dim >= path.Indices.Count())dim = path.Indices.Count() - 1;
GH_Path newPath = new GH_Path(path.Indices[dim]);
tmp.AddRange(tree.Branch(path), newPath);
}
tree = tmp;
}
The above … well … requires rather some IQ more (if you want to work on a blind date basis):
Imagine a path: {6,77,89,2} and a path {77,89,1,2} : if dim == 3 … then Houston we do have a problem. Or imagine paths like {7}, {6,7}, {89,0,7} … {45,67,7} and a dim value: 77 > a single path {7} is the result.
BTW: if GH_Path path = new GH_Path(6, 66, 666, 6666); then 6 is the first dimension, 66 the second … blah, blah.
BTW: path.Indices yields an int Array of size 4: {6, 66 , 666, 6666}
So this is maybe “better”:
public void ChangePath<T> (ref DataTree<T> tree, int dim, bool IQ){ // dim for dimension position
DataTree<T> tmp = new DataTree<T>();
List<int> dims = new List<int>();
foreach(GH_Path path in tree.Paths){
if(dim >= path.Indices.Count())dim = path.Indices.Count() - 1;
int pathDim = path.Indices[dim];
if(IQ && dims.Contains(pathDim)) continue; // or do something else
dims.Add(pathDim);
GH_Path newPath = new GH_Path(pathDim);
tmp.AddRange(tree.Branch(path), newPath);
}
tree = tmp;
}
Spend a couple of minutes for some sort of a simple demo on all that:
DataTree_ChangePath_EntryLevel_V1.gh (119.6 KB)