If you have a C++ DLL called CPlusPlus.dll with the following code
extern "C" // use this to prevent C++ name mangling: C# needs to call the function by its unmangled name
__declspec(dllexport) void CallCFunction(ON_Mesh* pMesh)
// do something in C++ with the mesh's double precision verts
ON_3dPointArray& doublePrecisionVerts = pMesh->m_dV;
public static class MeshExtensions
public static double ToDoubleArray(this Mesh mesh)
return new double;
var rc = new double[mesh.Vertices.Count * 3];
int index = 0;
for (var i = 0; i < mesh.Vertices.Count; i++)
var pt = mesh.Vertices.Point3dAt(i);
rc[index++] = pt.X;
rc[index++] = pt.Y;
rc[index++] = pt.Z;
You can use like this:
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
var filter = ObjectType.Mesh;
var rc = RhinoGet.GetOneObject("Select mesh", false, filter, out var objref);
if (rc != Rhino.Commands.Result.Success || null == objref)
var mesh = objref.Mesh();
if (null == mesh || !mesh.Vertices.UseDoublePrecisionVertices)
var doubles = mesh.ToDoubleArray();
foreach (var d in doubles)
I’d put the extension class inside your namespace.
More on extension methods:
If this is the case, then you must link with the version of openNURBS that comes with Rhino, not build and link some other version into your DLL. The easiest way to do this is to build a Rhino-dependent DLL.
This will require to integrate opennurbs into my cpp project, which after trying yesterday, didn’t succeed…
The doc on the website is not very clearly written and if I follow the process, differen’t kinds of errors always occur. For instance, this:
To be honest, I don’t exactly know. Maybe you can get a pointer, but you need to make sure that the garbage collector doesn’t touch it, so you need to pin the pointer until you ar done in c++.
If you search for terms like marshalling and pointer pinning, maybe something useful turns up.
Another thing to look at is what rhino provides in the Rhino.Runtime.Interop class and the interop wrappers