Check RhinoCommon version in GH?

Hi there!

I am writing a GH component that tries to use the NurbsSurface.CreateCurveOnSurface method, which the documentation specifies is available in version 6.20. However, the method seems not to be available in my C# script components or when loading RhinoCommon in VS.

I can check the assembly version by:

Version v = typeof(Curve).Assembly.GetName().Version;

Which gives me 6.20.19322.20361, so I am not sure what I’m missing. Is my GH using a different assembly version? Or is it just this method that wasn’t opened in 6.20.

As opposed to this, I can for example see the MeshThicknessMeasurement struct which apparently was also available as of 6.20

Thanks!

JL

What does your C# script look like?

Well, something like this… (sorry for huge dump! :sweat_smile:)

This is a function that would be running inside either a C# script component (//additional code) or as part of a compiled GH plugin component. See the commented out section.

  // This function takes a list of UV coordinates for a surface, and tries to equalize them
  // along a given direction.
  List<Point2d> EqualizeUVPtsOnSurface(Surface surface, List<Point2d> uvPoints, int uCount, int vCount, int direction){

    // First, prepare some data based on the chosen direction.
    int dirCount, perpCount;
    List<Point2d> uvPts;

    if (direction == 0)
    {
      dirCount = uCount;
      perpCount = vCount;

      // Clone the incoming list
      uvPts = new List<Point2d>(uvPoints);
    }
    else
    {
      dirCount = vCount;
      perpCount = uCount;

      // Flip the grid the UV points
      uvPts = new List<Point2d>();
      for (int v = 0; v < vCount; v++) {
        for (int u = 0; u < uCount; u++) {
          int id = v + u * vCount;
          uvPts.Add(uvPoints[id]);
        }
      }
    }

    // Create interpolated curves with the UV points in the chosen direction.
    List<NurbsCurve > dirCurves = new List<NurbsCurve>();
    for (int i = 0; i < dirCount; i++) {
      List<Point2d> dirPoints = uvPts.GetRange(i * perpCount, perpCount);
      NurbsCurve dirCurve;

      //// This is supposed to work for Rhino 6 SR20, but it is not available?
      //// https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_NurbsSurface_CreateCurveOnSurface.htm
      //// See: https://discourse.mcneel.com/t/check-rhinocommon-version-in-gh/92673
      //dirCurve = NurbsCurve.CreateCurveOnSurface(surface, dirPoints, RhinoMath.ZeroTolerance, false);

      // Otherwise, let's define an interpolated curve in 2D UV domain,
      // and find it's 3D mapping on the surface by "pushing it up".
      // Must convert Point2d to Point3d first to feed them to CreateInterpolatedCurve.
      List<Point3d> pts = new List<Point3d>();
      foreach (Point2d p in dirPoints) {
        pts.Add(new Point3d(p.X, p.Y, 0));
      }
      Curve dirNormCurve = NurbsCurve.CreateInterpolatedCurve(pts, 3).ToNurbsCurve();
      dirCurve = surface.Pushup(dirNormCurve, RhinoMath.ZeroTolerance).ToNurbsCurve();
      dirCurves.Add(dirCurve);
    }

    // Find points at equal lengths on the direction curves.
    uvPts.Clear();
    foreach (NurbsCurve c in dirCurves) {
      Point3d[] pts;
      c.DivideByCount(perpCount - 1, true, out pts);

      double u, v;
      foreach (Point3d p in pts) {
        surface.ClosestPoint(p, out u, out v);
        Point2d uv = new Point2d(u, v);
        uvPts.Add(uv);
      }
    }


    // Before returning, if point order was flipped,
    // unflip it for consistency with the incoming data.
    if (direction != 0)
    {
      // Flip the order of the UV points
      List<Point2d> flippedPts = new List<Point2d>();
      for (int u = 0; u < uCount; u++) {
        for (int v = 0; v < vCount; v++) {
          int id = u + v * uCount;
          flippedPts.Add(uvPts[id]);
        }
      }

      uvPts = flippedPts;
    }

    // Done!
    return uvPts;
  }

You want NurbsSurface.CreateCurveOnSurface. The function is on the NurbsSurface class instead of NurbsCurve

Hahaha, OMG, that was really embarrassing… Seriously tempted to delete the post :slight_smile:

Thanks Steve!

1 Like

We have all done it :slight_smile:

1 Like