Level of data tree in Python or c#

How can I extract the level / depth of the branches of a data tree in Python or c#?

Or is there a way to extract the level with the Path Mapper?

Uploading images and files seems to be broken, I’ll try again later…

do you mean this property?

Yes, thanks that’s it.

I still cannot copy paste upload a screenshot.

I find it confusing that the Tree Statistics L output shows the number of items in a branch.

It seems length should instead show the number of branch path indices?

I tried to make the output like the input tree but something seems to be wrong.

I get the error: cannot convert from ‘Grasshopper.Kernel.Data.GH_Path’ to ‘int’ and I’m lost.

private void RunScript(DataTree<object> x, out object L)
{
    
  DataTree<int> myTree = new DataTree<int>();
  var y = x.Paths;
  GH_Path p;
  
  for (int i = 0; i < x.BranchCount; i++)
  {
    p = y[i];
    myTree.Add(x.Paths[p].Length);
  }

  L = myTree;

}
private void RunScript(DataTree<Curve> x, ref object L)
  {
    var myTree = new DataTree<int>();
    var y = x.Paths;
    for (int i = 0; i < x.BranchCount; i++)
    {
      myTree.Add(y[i].Length, x.Path(i));
    }
    L = myTree;
  }
1 Like

If you deconstruct the path and use length afterwards, it should give you that number

That’s what I’ve been doing for a few years now. But I think it’s wrong.

Thanks @ThomasE this works now.