C# Point array to C++

I’m trying to get an array of points from C# to C++, but it doesn’t seem that there is a publically accessible interoperable type to do so. Going off of the C# api live on github, I can seee that PullPointsToSurface uses Rhino.Collections.Point3dList.GetConstPointArray() to pass points to a native function, however GetConstPointArray() is an internal type and cannot be accessed outside of rhino common itself.

Is there any way I can do this in my own dll?

Thanks in advance.

Hi @db368,

I haven’t tested this. But this should work.

public bool TestPointCloud(IEnumerable<Point3d> points)
{
  if (null == points || !points.Any())
    return false;

  var pointArray = points.ToArray(); // LINQ
  var pointCount = pointArray.Length;
  return UnsafeNativeMethods.RHC_TestPointCloud(pointCount, pointArray);
}

public static class UnsafeNativeMethods
{
  [DllImport(Import.lib, CallingConvention = CallingConvention.Cdecl)]
  internal static extern Guid RHC_TestPointCloud(int pointCount, Point3d[] pointArray);
}

RH_C_FUNCTION bool RHC_TestPointCloud(int pointCount, /*ARRAY*/const ON_3dPoint* pointArray)
{
  bool rc = false;
  if (nullptr != pointArray && pointCount > 0)
  {
    ON_PointCloud point_cloud;
    point_cloud.Append(pointCount, pointArray);
    // TODO...
    rc = true;
  }
  return rc;
}

– Dale

1 Like