C# Extend Mesh Ngon Class

Hi,

I would like to ask how can I extend Mesh Ngons Class?

What I would like to do is when I write MyWonderfullMesh.Ngons. here I would like to have more methods.

Currently I am writing public static method for Mesh, but it became too messy, since it mixes up with normal mesh methods.

1 Like

Do you mean you are creating extension methods?

Yes, but annoying part is that extension methods is written like this:

public static void WonderfullMethod (this Mesh mesh){
 dosomething();
}

so these methods appear on MyWonderfullMesh.WonderfullMethod .
but not on MyWonderfullMesh.Ngons.WonderfullMethod

The thing is that I need to have access of mesh itself in that method, but from user persective I would like to keep it under NGons name.

Is it possible?

Create an extension method on MeshNgonList instead:

https://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_Geometry_Mesh_Ngons.htm

public static void EvenWonderfullerMethod(this MeshNgonList ngons) {
    ExceedExpectations();
}

Thanks Nathan, but MeshNGonList does not have any information about Mesh itself so I cannot now its mesh vertices positions, edge id and etc. I think I am doing something wrong.

You could always work around that by having an extra parameter to the function that takes the Mesh too.

This would look like this then:

MyMesh.Ngons(MyMesh), thanks Nathan for help, I will change the naming, as going to Ngons collections makes it a bit more messier.

Yes.

I see three ways how to handle:

  1. Don’t care, just continue as you did before
  2. Give your methods clear names: NgonsWonderfulOperation(), continue otherwise as you did before
  3. Do the extension on the collection and pass in the Mesh as well.

I guess you’re going for 2. now?

Yup, Thanks:)