Petras1
(Petras Vestartas)
May 3, 2019, 9:00am
1
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
nathanletwory
(Nathan 'jesterKing' Letwory)
May 3, 2019, 9:04am
2
Do you mean you are creating extension methods?
Petras1
(Petras Vestartas)
May 3, 2019, 9:06am
3
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?
nathanletwory
(Nathan 'jesterKing' Letwory)
May 3, 2019, 9:30am
4
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();
}
Petras1
(Petras Vestartas)
May 3, 2019, 9:36am
5
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.
nathanletwory
(Nathan 'jesterKing' Letwory)
May 3, 2019, 9:37am
6
You could always work around that by having an extra parameter to the function that takes the Mesh too.
Petras1
(Petras Vestartas)
May 3, 2019, 9:40am
7
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.
nathanletwory
(Nathan 'jesterKing' Letwory)
May 3, 2019, 9:45am
8
Yes.
I see three ways how to handle:
Don’t care, just continue as you did before
Give your methods clear names: NgonsWonderfulOperation(), continue otherwise as you did before
Do the extension on the collection and pass in the Mesh as well.
I guess you’re going for 2. now?