ghhops.HopsSurface > Rhino.Geometry.Surface access to ClosestPoint

Hi there, I am attempting to pass a nurbs surface to hops server component and need to evaluate the curvature at a given point. However I can’t seem to figure out how to use the Rhino.Geometry.NurbsSurface methods on the wrapped component. The code below throws the following, any help is appreciated:

1. Exception occured in handler:
'rhino3dm._rhino3dm.NurbsSurface' object has no attribute 'ClosestPoint'
  File "C:\Users\cawn069856\gits\PH-CPF_python\initMesh.py", line 37, in createMesh
    startPt = srf.ClosestPoint(initPoint)


import os
import numpy as np
from scipy import sparse
import ghhops_server as hs
from flask import Flask
# import rhino3dm

import rhinoinside

rhinoinside.load()
import Rhino

path = os.getcwd()

app = Flask(__name__)
hops = hs.Hops(app)

#set constants

@hops.component(
    "/initMesh",
    name="initMesh",
    description="Initialize mesh along lines of principal curvature",
    inputs = [
        hs.HopsSurface("Surface", "S", "Input surface"),
        hs.HopsNumber("length", "L", "edge length"),
        hs.HopsPoint("startPoint", "sp", "starting point for walk")
    ],
    outputs = [
        hs.HopsVector("dir", "v", "output vector (debugging)")
    ]
)
def createMesh(srf, l, sp):
    initPoint = Rhino.Geometry.Point3d(sp.X, sp.Y, sp.Z)
    print(dir(srf))
    
    startPt = srf.ClosestPoint(initPoint)

    curvature = srf.CurvatureAt(*startPt)
    minDir = curvature.Kappa(0)
    return minDir

Well was that ever painful!

To resolve the issue I had to collect the surface points and create a new Rhino.Geometry.NurbsSurface whereupon I was able to evaluate the nearest point (also converted from hs.HopsPoint to Rhino.Geometry.Point3d) and then put out the vector… so baby steps but at least it’s working. In case anyone else is interested here’s the code (apologies for my poor organization!)

import os
import numpy as np
from scipy import sparse
import ghhops_server as hs
from flask import Flask

import rhinoinside

rhinoinside.load()
import Rhino
import System

path = os.getcwd()

app = Flask(__name__)
hops = hs.Hops(app)



@hops.component(
    "/initMesh",
    name="initMesh",
    description="Initialize mesh along lines of principal curvature",
    inputs = [
        hs.HopsBrep("Surface", "S", "Input surface"),
        hs.HopsNumber("length", "L", "edge length"),
        hs.HopsPoint("startPoint", "sp", "starting point for walk")
    ],
    outputs = [
        hs.HopsVector("dir", "v", "output vector (debugging)")
    ]
)
def createMesh(srf, l, sp):

    pts = System.Collections.Generic.List[Rhino.Geometry.Point3d]()

    numU = srf.Points.CountU
    numV = srf.Points.CountV
    for i in range(numU):
        for j in range(numV):
            select = (i,j)
            point = srf.Points.__getitem__(select)
            ptAdd = Rhino.Geometry.Point3d(point.X, point.Y, point.Z)
            pts.Add(ptAdd)
    
    surface = Rhino.Geometry.NurbsSurface.CreateFromPoints(pts, int(numU), int(numV), 3, 3)
    testPt = Rhino.Geometry.Point3d(sp.X, sp.Y, sp.Z)
    
    startPt = surface.ClosestPoint(testPt)
    print(startPt)

    curvature = surface.CurvatureAt(int(startPt[1]), int(startPt[2]))

    vecOut = curvature.Direction(0)
    print(vecOut)

    dirOut = {"X": vecOut[0],
        "Y": vecOut[1],
        "Z": vecOut[2]}
    print(dirOut)

    return dirOut