Grasshopper

algorithmic modeling for Rhino

"List<>" data structure in C#.NET component + how to manipulate the output parameter

Hello,

1.

I am having a hard time understanding what is the data structure of a list (of points or lines or Xforms) that comes as an input to C# component.

 

Actually I have inputted a list of 10 points. I want to access every single point. what are the syntaxes to address them. For example I tried myPoints(3) or myPoints[3] or myPoints.point(3) but they didn't work.

 

I know there is this method to use a "foreach (On3dPoint in x)" loop, but I wondered if there is a way to precisely address them like an array,to later store them in arrays or use them in known-limit loops.

 

I have the same question for Xforms, it there a way to access certain points or faces or lines of an Xform?

 

2.

Why the output type of a C# sharp component could not be changed? Is is possible to output a list of lines and later use them in other GH components?

Many thanks in advance,

 

Mbnq

Views: 5714

Replies to This Discussion

Hello,

 

[EDIT: I just realised that you are talking about the C# component within grasshopper. I gave you the instructions for making your custom component. If you are unable to figure out what to do from this, let me know. In the meanwhile, I will type out the correct solution. Sorry!!]

 

First you need to register the input parameter within the RegisterInputParams() method in this manner:

pManager.Register_PointParam("Points List", "P", "List of 3D points", GH_ParamAccess.list);

The GH_Param.Access.xxxx defines whether its a single item, list or a tree input.

 

In the SolveInstance() method, you can access the list by typing the following:

List<Rhino.Geometry.Point3d> myPointsList = new List<Point3d>();           

DA.GetDataList<Rhino.Geometry.Points>(0, myPointsList);

 

You can either access them as array by doing this (what I prefer):

for (int index = 0; index < myPointsList.Count; index++)           

{               

Point3d option1 = myPointsList[index];             

//or 

Point3d option2 = myPointsList.ElementAt(index);

}

 

Or in this way:

Point3d[] myPointsArray = myPointsList.ToArray(); //Then use a for loop again

 

Here you go! Hope it is clear now.

And sorry about the confusion earlier!

Attachments:

Great, many thanks, that works pretty well. And I should say yes the first answer was so much technical for me.

The only thing I needed was to translate your definition to a .NET version using onLine and on3dPoint. And now it works well. 

Now I am heading for Xforms and ...

But meanwhile I came to this question what is the difference of C# and C#.NET components other than just the way we call rhino classes?

 

Haha....I just noticed that there were two different C# components :-D

From what I can see, the difference is with the libraries that the components are using. The Legacy component uses the older version of the Rhino SDK and also doesn't include the GH_IO library. So it seems like the C# component with the newer version has more features/is more flexible than the Legacy component.

 

 

Yes it seems so, and so far the namings are pretty organized and logical!

Just after reading this I am getting back to what you told in the first answer, still far from making my own component. But I would try soon maybe!

All in all thanks for your great responds,

 

Mobasher

Glad to help :)

If you plan to write your own component, you should download the Grasshopper SDK (Grasshopper -> Help -> Download SDK Help), it contains a few examples as well. 

Good luck!

 

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service