Grasshopper

algorithmic modeling for Rhino

Hi,

I haven't been able to find an answer to this from crawling the forum or Googling...

I am sorting out casts of a more complex class to basic datatypes to enable accessing different bits of the object easily. Casts to single types work fine - even lists of Breps or Meshes can be amalgamated into a single one and then cast as a single Brep / Mesh. The issue is when trying to cast to a list of objects - i.e. an array of Curves.

Is this possible? Is there a Goo type that I am missing for handling cases such as this? Sample code below...

public override bool CastTo<Q>(ref Q target)
{

if (typeof(Q).IsAssignableFrom(typeof(List<GH_Curve>)))
{
Curve[] crvs = Value.Blank.GetAllGlulams().Select(x => x.Centreline).ToArray();
target = crvs.Select(x => new GH_Curve(x)).ToList() as Q; < Can't cast List to Q.

return true;

}

if (typeof(Q).IsAssignableFrom(typeof(GH_Curve)))
{
Curve[] crvs = Value.Blank.GetAllGlulams().Select(x => x.Centreline).ToArray();
target = (Q)crvs.Select(x => new GH_Curve(x)).ToList(); < This obviously doesn't make sense, unless GH_Curve has some support for casting to lists / arrays.

return true;

}

return base.CastTo<Q>(ref target);

}

Views: 89

Reply to This

Replies to This Discussion

No casting is always a one-to-one operation. It doesn't work on lists (many-to-many) or mixed (one-to-many or many-to-one). For this you will have to supply specific conversion components.

Cheers, David! I suppose I'll go that route or try to think of something else :)

RSS

Translate

Search Grasshopper

Photos

  • Add Photos
  • View All

© 2017   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service