Hello there,
I have been struggling to make a tree based on another with searching for a specific item in the tree and finding out about the indices of those in the same tree structure but so far I couldn’t find an efficient way to do it with a c# component. Can anyone help me with this?
My code is:
private void RunScript(string x, DataTree<string> y, ref object A)
{
DataTree <int> stringTree = new DataTree<int>();
var paths = y.Paths;
foreach( var j in paths)
{
var newpath = stringTree.EnsurePath(j);
foreach ( var k in stringTree.Paths)
{
if (k == j)
{
foreach (List<string> branch in y.Branches)
{
List<int> newLists = new List<int>();
foreach (var i in branch)
{
var text = i.ToString();
var index = branch.IndexOf(text);
if (text.Contains(x))
{
newLists.Add(index);
stringTree.AddRange(newLists, k);
}
}
}
}
}
}
A = stringTree;
as you can see I get wrong result. It would be nice if someone tells me where I am going wrong.
Thanks alot!
questionC#GH.gh (9.9 KB)