Grasshopper

algorithmic modeling for Rhino

Hi to all 

How can i cast IGH items  ? 

the cast in this code does not work 

the objects selected are simple lines in rhino 

List<IGH_GeometricGoo> geometry = new List<IGH_GeometricGoo>();
if ((!DA.GetDataList(2, geometry)))
return;

for (Int32 i = 0; i < geometry.Count ; i++)
{
if ((geometry[i] == null))
continue;


  GH_Curve crvObj;
  if (geometry[i].CastTo(out crvObj))  //fails 
  {
      ... 
 
  }
}

any help  on this item ? 

thanks 

gerry 

Views: 1852

Replies to This Discussion

Hi Gerry,

are you sure you want to use goo derived types? You could just ask for a List<Rhino.Geometry.Curve> or List<Rhino.Geometry.Line> if you're sure that's what you've got.

The CastTo and CastFrom methods are used primarily by Grasshopper to perform conversions that are not already known by the core product (for example if someone adds a new data-type which can be converted to a Brep, they can choose to implement that casting logic by overriding CastTo on their Goo class).

If you're dealing with standard RhinoCommon data types the best way is to use the methods in Grasshopper.Kernel.GH_Convert.

--

David Rutten

david@mcneel.com

Tirol, Austria

Hi David 

Well Since I am a newbie in c# not sure how to get back data from those lists 

 I am just following what I am used to ( c++ casting )

I did not find any example so going trough all kind of casting in the attempt to get back 

a bunch of curves and polylines on which I have attached user data 

a simple snippet on how to get  back geometry  could save me a headache 

thanks 

gerry 

If the input parameter is a Curve parameter, then you can use:

List<Curve> curves = new List<Curve>();

if (!DA.GetDataList(0, curves)) return;

This should give you mutable instances of the curves inside the input parameter. I think userdata should be intact as well.

If you ask for regular types such as Rhino.Geometry.Curve or Rhino.Geometry.Brep, you get shallow copies of the actual OpenNurbs geometry. As soon as you modify these instances an OpenNurbs duplicate of the geometry will be created behind the scenes and the changes will be applied to that.

If you ask for IGH_Goo derived types then you get the actual data which is in the input. This data may be shared with any number of other parameters so you have to make a copy of it yourself before -say- transforming it.

It is almost always better to ask directly for the type you're interested in and leave the IGH_Goo types to Grasshopper. There are however rare occasions when you do need the real data, in which case you have to be very careful about it.

The SDK documentation does have an example for components with List parameters, have you downloaded the SDK docs yet? You can do so via the Grasshopper help menu.

--

David Rutten

david@mcneel.com

Tirol, Austria

Thanks David

that worked fine 

gerry 

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