Grasshopper

algorithmic modeling for Rhino

Hi,

How can I correctly cast GH_Mesh to Rhino.Geometry mesh in the line marked below?

foreach (System.Object g in this.input)

{

 if (g.GetType() == typeof(Grasshopper.Kernel.Types.GH_Mesh)) meshesSorted.Add((Mesh)g);

// error 1. Solution exception:Unable to cast object of type 'Grasshopper.Kernel.Types.GH_Mesh' to type 'Rhino.Geometry.Mesh'.

 

}

Thanks:)

Views: 1143

Replies to This Discussion

a goo type usually has a .Value property that represents the underlying geometric type.

Be careful that if you do not duplicate data and then change it, it may also change in unexpected places. The GH SDK typically has safe-guards against this sort of conflict, but by getting IGH_Goo instances and accessing their Values directly, you circumvent those safe-guards.

Mesh m;
new GH_ObjectWrapper(g).CastTo(out m);
meshesSorted.Add(m);

This works for me. 

If you could show me how to work with value property I would very glad to learn:)

GH_ObjectWrapper is typically only used to deal with data which does not have its own goo type. Meshes do, in the form of GH_Mesh.

Constructing a new GH_ObjectWrapper just to call CastTo is pretty a pretty roundabout way to achieve the goal.

If g is of type GH_Mesh, then

Mesh m = g.Value;

if (m == null)

  return;

m = m.DuplicateMesh(); // Only needed if you're going to change the state of m.

m.XXXXXX();

Thank you:)

you know it took me ages to reach this workflow re conversions. lots of tears. 

for those prototyping functionality in c# scripting comps and then heading to visual studio, in the scripting components you actually get the obj.value directly...

Yes one functionality provided by IGH_Goo is to create 'script safe' instances of data, so that values can be handed off to scripters without worries that changes they make percolate back up the stream.

Meshes and Breps are duplicated (shallowly) before given to C# and VB scripters, which is a layer of protection not given to those developing code on Visual Studio.

I'm hopeful conversions in GH2 will be easier to deal with, not in the least because the IGH_Goo paradigm has been ditched and data is now just stored directly as the original type in trees.

But does it work when I have a list of System.Object?

When I take object g I cannot see Value.

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