Grasshopper

algorithmic modeling for Rhino

I have a method that works on GH_Structure 's. The general method accepts asks for GH_Structure<IGH_Goo> as i need it to be versatile.

I found there is a method GH_Structure<whatever>.DuplicateCast<whatever>()

but somehow i don't manage to make it work. Any hint somebody.

Thanks in advance.

Manuel

I think there should should be somewhere a repository for leaving PHYSICAL beer to all the people helping in the forum by the way, THANKS A LOT GUYS. LIKE THE FORUM

Views: 837

Replies to This Discussion

Hi,

It's not possible to do that by casting.

GH_Structure<GH_Point> does not derive from GH_Structure<IGH_Goo> they are just instances of the same template class.

You'll have to create a new GH_Structure and do the casting on each one of the inner elements and in your case it's possible only because they DO derive.

Yes It is right what you say.

But i found a method of the class GH_Structure, it is called DuplicateCast which is meant to do that. The problem is that I somehow don't figure out how to use it, it somehow has a tricky sintax.

Thanks.

Manuel

You could use the DuplicateCast method, you'll have to supply a conversion delegate.

private IGH_Goo conversion(GH_Point data)

{

  return data; // easy since GH_Point already implements IGH_Goo.

}

pass in a reference to this method to DuplicateCast and it should work.

--

David Rutten

david@mcneel.com

Thanks David.

You earned the first beer in the repository.

It is exactly what I wanted, but I am not still familiarized with delegates, but it worked.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service