Passing And Using Custom Classes

[[EDIT: SEE SECOND POST]]

Hi All,

Here’s an easy one that is a C# problem not a Grasshopper one - per se - but I’ve been banging my head on it and your GH specific advice would probably break the logjam more quickly than I’ve been able to.

The question, put simply, is how do I index with [] on a method group?

I’ve followed this tutorial and it works well for packaging up the data and sending it to the next component using GH_ObjectWrapper.

So here’s the relevant code snippet:

    internal static GH_Structure<GH_Point> CellRootNodesArrayBased()
    {
//  A class containing data describing the whole lattice - generated upstream
        Lattice l = new Lattice();

//  A class containing attributes of an individual cell of the lattice - generated upstream
        LatticeCell lc = new LatticeCell();

//  A string describing the cell "centering" 
        string classCentering = lc.Centering;

//  DataTree of the cartesian locations of the points
        Grasshopper.DataTree<double[]> nodeTree = l.LocationTree;

//  DataTree containing lists of paths to the points within the lattice which describe the 
//  vertices of a cell. 
        Grasshopper.DataTree<GH_Path> lCIT = lc.CellIndexTree;    

//  THIS LINE IS WHERE MY ERROR IS HAPPENING               
        GH_Path localPath = lCIT[(lCIT.Branch[0]),0];

//  Local Root Vertex – the point to be determined from this program and inserted to a tree to be passed
        GH_Point lRV = new GH_Point();

//  NOTE, this code for the assignment of values to the points is all old, 
//  based on looking up x,y,and z from a 3 element array that was on a list. 
//  This will change based on the syntax to access the proper branch of the tree I’m 
//  asking for your help on above, but I wanted to include it so you understand the goal. 
//  Obviously I need to be able to access the right Branch {x;y;z} before I access the right 
//  list item (double[3])and element of that array.
        var p00 = new Point3d(lCIT[0][0], lCIT[0][1], lCIT[0][2]);
        var p06 = new Point3d(lCIT[6][0], lCIT[6][1], lCIT[6][2]);

//  I creates a point at the center of the cell
        if (classCentering == "I")
        {
            var p14 = (p00 + p06) / 2;
            GH_Convert.ToGHPoint(p14, 0, ref lRV);
        }

        else
        {
        }

//   lRVT = Local Root Vertex Tree
        var = new GH_Structure<GH_Point>();
        lRVT.Insert(lRV, localPath, 0);
        lc.RootVertexTree = lRVT;
        return lc.RootVertexTree;
        }

So obviously, I’m getting “no argument given” errors re: the path in the point creation. Once I fix the big problem that’ll sort out.

The one that’s tripping me up is "Cannot Apply indexing with [] to an expression of type ‘method group’ on the line where I assign a value to localPath from the (local) Cell Index Tree, which is referenced in from the class Lattice Cell, which has been invoked locally as lc.

The core issue seems to be just a simple syntax mistake, and your patience and help is very appreciated.
Thanks in advance!

Duane

Also to note, I tried passing this all as GH_Structure elements, but there were other, worse problems arising. Here all the data is in the right places, I’m just having trouble accessing it properly.

Iterating with a for loop fixes the syntax problem. There’s a different object reference problem, but if I can sort out what’s not looking the right place for data, I will report back with the solution to my own problem…

Branch() is a method, you need to call it, not index it. Or you can index Branches[0] to get the first branch of the tree. Branch(0) will only make sense if you actually have a branch with Path {0}.
I don’t fully understand what that line does, but that explains your error.