How can I get a list as output in C#?

New user of Grasshopper 3D here,
and my problem is that I created a component that generates some Points, this component run 26 times (for example) because I gave him 26 inputs. The thing is I want a list of this 26 ouputs instead of the 26 points because I want to use them all together to iterate through the list for the next component that I’m coding.

Declare that input as List.

Anyway ALWAYS post something since problem solving via an Image is not yet invented.

1 Like

I changed the input and I’m still getting an invalid cast
image

This is the Generate Matrix component

The Ray | Surface - uv floor output is a Point2d

Maybe I was not clear enough: POST the C# (in a test gh file) that refuse to do things. Plus a CLEAR description about what you are after.

It looks like the problem is not with the output of the previous component, but the input of your ‘Generate Matrix’ component.
In RegisterInputParams you need to use GH_ParamAccess.list for the param, and in SolveInstance use GetDataList instead of GetData.

1 Like

Thank you Daniel,
but now I get invalid cast Point>>Point2d


image

I’m sorry I don’t think this is the exact thing you want but I don’t know how to upload this in a gh file so I upload the full C# code.
GhGenerarMatriz.cs (2.8 KB)

Full Description: I want to generate a Matrix via 2 inputs, these inputs are a list of uv Points and a surface (plane surface). I need the surface to calculate the rows and columns of the matrix.
With this I want to go though the list to fill the matrix, if there is an uv point {1,1} I want to add +1 to the position [1,1] of the matrix, if there is a {1,2} it will add +1 to the [1,2] position etc.
This component will call a Method called GenerarMatriz(Points2d, surface) that does this work.

So after this description my problem is that the component Ray | Surface (intersect a ray with a surface) calculates this uv intersection points and I need these points to generate the matrix but when I try to input them I get the invalid cast.

I did this How can I get a list as output in C#? - #5 by DanielPiker but now i get Point>>Point2d invalid cast.

Ah, I hadn’t noticed you’re using Point2d.
Probably the easiest way here is to use AddPointParameter instead of Generic, (and GetDataList<Point3d>), then you get a list of Point3d (and can just ignore the Z part in the bits you do next).

1 Like

Yes! worked with Point3d.
Thank you Daniel!

1 Like

Given the opportunity:

  1. If you want some sort of “visual map” of a Tree to a Matrix … see comments in the attached.

  2. Ray3d DOES not work on BrepFaces … thus see Method used .

Matrix_MapCcxPtsTree_To_Matrix_V1.gh (157.9 KB)

1 Like