Open Maya - getClosestPoint() . How to use it in custom node?

Hi,

I would like to create maya python node that in calculation use getClosestPoint() procedure. The main problem is how to load mesh name to node. I would like to have ability to change input mesh.

ex. code in python:


import maya.api.OpenMaya as OpenMaya
import pymel.core as pm
 
geo = pm.PyNode('pSphere1')
loc = pm.PyNode('locator1')
pos = loc.getRotatePivot(space='world')
 
try:
    selectionList = OpenMaya.MSelectionList()
    selectionList.add(geo.name())
    nodeDagPath = selectionList.getDagPath(0)
except:
    raise RuntimeError('maya.api.OpenMaya.MDagPath() failed on %s' % geo.name())
 
mfnMesh = OpenMaya.MFnMesh(nodeDagPath)

point = OpenMaya.MPoint(pos.x, pos.y, pos.z)
space = OpenMaya.MSpace.kWorld

 
closestPoint= mfnMesh.getClosestPoint(point, space)  
cpx = closestPoint[0][0]
cpy = closestPoint[0][1]
cpz = closestPoint[0][2]


Is there possibility to use something different than name as input ex. outMesh ? worldMesh ? So i can use it as an input channel in my node.

regards,
k.

ok i found solution for mesh as an input. Now im looking for procedures that works on nurbsSurface

       
        goal = OpenMaya.MPoint(data.inputValue(self.aGoal).asFloatVector())
        inputColliderMesh = data.inputValue(self.aInputColliderMesh)             
        meshColl = inputColliderMesh.asMesh()
        mFnMeshColl = OpenMaya.MFnMesh( meshColl )  
        closestPoint = OpenMaya.MPoint()    

        #collider mesh as input      
 
 
        #if inputColliderMesh.type() == OpenMaya.MFnData.kMesh:
        
       
 
        space = OpenMaya.MSpace.kWorld
        
        mFnMeshColl.getClosestPoint(goal, closestPoint, space)