Grasshopper

algorithmic modeling for Rhino

Dear all,

I try to use a list of PolylineCurve as input values for my component. The data come from another component where I have created a list of PolylineCurve as output. Any idea what went wrong that I only get a list of GH_Curve as input? I used the following code:

            List<object> blocksAsCurve = new List<object>();
            if (DA.GetDataList(0, blocksAsCurve))
            {
                foreach (object curCurve in blocksAsCurve)
                {
                    if (curCurve != null)
                    {
                        var type = curCurve.GetType();
                        if (type == typeof(Grasshopper.Kernel.Types.GH_Curve))
                        { ...

(object was only used to see which type I get at all...)

Many thanks and best regards

Reinhard

Views: 387

Replies to This Discussion

At least I found how to cast the GH_Curve to a PolylineCurve:

            List<GH_Curve> blocksAsCurve = new List<GH_Curve>();
            if (DA.GetDataList(0, blocksAsCurve))
            {
                foreach (GH_Curve curCurve in blocksAsCurve)
                {
                    if (curCurve != null)
                    {
                        Curve tempPoly;
                        curCurve.CastTo<Curve>(out tempPoly);
                        PolylineCurve blockPoly = (PolylineCurve)tempPoly;

But I would still be interested why the input is not a PolylineCurve. At another component I have an input List<Curve>, which gets the data from a component that has a List<Curve> as output. This works fine as expected...

All data exchanged between components and stored inside parameters must implement the IGH_Goo interface. This interface allows Grasshopper to do certain things with the data such as display it as a string, read and write it to *.gh files, convert it to other types, provide a human-friendly description and type name to the user, duplicate it, transform it, etc.

Obviously Grasshopper uses a lot of standard types it does not itself define. Both types from the .NEt framework (bool, string, double, System.Drawing.Color) and types from RhinoCommon (Point3d, Curve, Brep). For these types of data, a specific wrapper class is designed which contains the original data but implements IGH_Goo. Examples here are GH_Curve which can wrap any type that derives from Rhino.Geometry.Curve, GH_Integer which contains a System.Int32 value, and GH_ObjectWrapper which does its best to provide functionality for unknown types.

Mostly you can ignore the wrapper classes and just work with the underlying type instead, but sometimes (especially when using GH_Structure[T]) you have to deal with IGH_Goo itself.

Dear David,

many thanks for the explanation.

Best regards

Reinhard

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