Can't access mesh properties

Hi , Why can’t I access the mesh properties although I haven’t missed Grasshopper and Rhino using directive (I’m using VS 2015) ?

Thank you so far.

Because iMesh is not a mesh, it’s a list of meshes.

Thank you David , I tried to write down this one for list of meshes , but I don’t know if it’s the proper way ?

List<Mesh> iMesh = new List<Mesh>();
        DA.GetDataList(0, iMesh);

        List<Point3d> meshVertices = new List<Point3d>();

        foreach (Mesh i in iMesh)
            foreach (Point3d j in i.Vertices)


        DA.SetDataList(0, meshVertices);

If you want to collect all the vertices from a bunch of meshes into a single, flat list, that’s one way to do it yes.

I actually wanted the vertices in separate trees but i don’t know how set trees in c# ?

What is the use of it? Is the components purpose to output each mesh’s verts on a different branch? If so then you can set the input to be item rather than list. Or is something happening with these verts in the code afterwards that requires them to interact where a tree output is required?

Related to the original question you can look at this method.
and do the flat list of all verts like this as an alternative.

List allVerts = new List();

for(int i = 0; i < M.Count;i++)
  Point3d[] verts = M[i].Vertices.ToPoint3dArray();

As @Michael_Pryor said, if you just want vertices in trees, use item access for your mesh input.

To output trees, you must set the access of the output to tree, and create and populate a GH_Structure<GH_Point>. This is how data trees are stored internally. But it becomes complicated because you have to make sure the tree paths do not conflict when your code runs multiple times because someone inputs more than one list of meshes.

It’s probably best if you tell us exactly what you need to do.

Actually there is a list of mesh boxes that i want to extract each one’s four upper vertices and output them in separate branches

in that case just use item, not list. And find the 4 points for the mesh (how do you define these points, is it by height?). The component will run for each mesh input and will handle the branch output itself.


Thanks Mike it’s working , and I’m caring to know what is the proper way to find the 4 top vertices (by height) ? Do I have to extract Z coordinate or any better way ?

Depends on the situation and what you mean by top. Are the boxes always oriented to the world coordinates?

In fact , i can say the four vertices that has the larger Z Coordinate Value (top four )

If the case is really that it is always the top 4, then one way is something like this:

//Remove overlapping verts
M.Vertices.CombineIdentical(true, true);

//Get all the mesh verts
Point3d[] verts = M.Vertices.ToPoint3dArray();

//Get all the mesh verts z values
double[] vertsZ = new double[verts.Length];
for(int i = 0; i < verts.Length; i++)
  vertsZ[i] = (verts[i].Z);

//Sort the verts by the z values
Array.Sort(vertsZ, verts);

//Reverse the sorted vert array order

//List of top 4 points
List<Point3d> vertsTop = new List<Point3d>(){verts[0], verts[1], verts[2], verts[3]};

Thanks again Mike , I’m trying to extrude the surface that is created from these vertices I searched through extrusion methods and the only thing I found is CreatePeriodicSurface method , but how to use it and what does the input direction want ?

        NurbsSurface topSrf = NurbsSurface.CreateFromPoints(vertsTop , 2 , 2 , 3 , 3);

        Surface extrudedSrf = Extrusion.CreatePeriodicSurface(topSrf, -10 );