Accessing Number of Branches

Hi All, I hope everyone’s staying healthy and safe in these crazy times.

I have a script which writes data to a 3-level nested tree {a,b,c}
I’m trying to find the number of unique path numbers in each “dimension,” a b and c.
[edited to add - I’m writing this in C#]

Imagine this as the addresses in a 3 dimensional grid. Say a is 3, b is 4, and c is 5. I would have lists

{0,0,0}
{0,0,1}
.
.
{0,1,0}
{0,1,1}
.
.
{0,1,4}
{0,2,0}
.
.
on to
{2,3,4}
{2,3,4}

So as you can guess, I don’t want a count of paths with that dimension (as that would just be 60 (3x4x5) for all three), I want those values to return 3,4, and 5. Or, it could be thought of as the largest value for any given branch of a path.

I tried Branches[n].Count and Paths[n].Length (where n is the integer of the number of the path) and it just returns a value of 3…

Basically, what I’m trying to do is test for a condition so that on every path with a {3,n,n}, {n,4,n}, or {n,n,5} in it something happens.

It seems like both count and length would also return the product of 3x4x5, as each of the (3) indices of the paths at {a, , } repeats (4x5) times. So I would need to find the max number in each dimension, or the size of the set of each unique dimension a, b, or c of the path.

As for a code sample that would help facilitate this, there’s nothing I could add that would help, as I’m generating these trees in a different component and trying to bring them in to this component and operate over them. If I were doing this test in the component where the trees are generated this would be easy, but I’m trying to split different functions to different components.

Thanks in advance for any advice!

I’m guess you want path mapper:


set the 0 in the position you want to check.
then use a tree statistics to get the number of paths.

Hi Christopher, thanks for your help.

And my apologies because it certainly seems I wasn’t clear in my initial post - I’m talking about doing this in C#. I’ll update the post to reflect this.

Path mapper in gh would be quite simple, indeed. But alas, I’m trying to do this inside the C# code.

Thanks again for the generosity of your time!

I think the following code should be what you are looking for, although it uses System.Linq and Math libraries. temp is my GH_Structure that I am operating on.

List<GH_Path> p = temp.Paths.ToList();
int[] max = new int[3] { 0, 0, 0 };
for(int j = 0; j < p.Count; j++)
{
    max[0] = Math.Max(max[0], p[j][0]);
    max[1] = Math.Max(max[1], p[j][1]);
    max[2] = Math.Max(max[2], p[j][2]);
}
max[0] += 1;
max[1] += 1;
max[2] += 1;

max will hold the 3 dimensions and assumes there are no skipped values. Otherwise use a list for each index and count the distinct values.

Hi Christopher. That’s perfect. The only piece I was missing is the .ToList() method.
I have some small typos bugs to fix and I’ll post my snippet. Thank you!

internal static int Dimensions()
{
//  A local copy of the GHStructure of Lists of X,Y,and Z values of each point
var lGHFLT = GHFullLocationTree;

//  Creates a local List of all of the paths
var lPL = lGHFLT.Paths.ToList();

for (int j = 0; j<lPL.Count; j++)
    {
        dX = Math.Max(dX, lPL[j][0]);
        dY = Math.Max(dY, lPL[j][1]);
        dZ = Math.Max(dZ, lPL[j][2]);

        if (dX<lPL[j][0])
        {
            dX++;
        }

        if (dY<lPL[j][1])
        {
            dY++;
        }

        if (dZ<lPL[j][2])
        {
            dZ++;
        }
    }
    return dX;
    return dY;
    return dZ;
}

And that’s it. Thank you so much for the suggestion to use the Paths.ToList method and just iterate over it. Simple solution, very efficient.

Now all I have to do is actually learn how to pass custom classes and it’s redundant because my Count in that dimension just comes through. But that’s after I get a working prototype of the rest of my library. Thanks again!