Definitely, you should try using closestPointOnMesh. I used it for the same reason. This guaranteed that, on a triangulated model, I would never have to check more than three verts. Here is a piece of code ripped from my script...
////////////////////
//Get the verts of closest face to this point
int $closestFace = closestPointOnMesh -ip $vertexInDataSplitFloat[0] $vertexInDataSplitFloat[1] $vertexInDataSplitFloat[2] -q -f $selectedObject
;
select -r ($selectedObject + ".f[" + $closestFace + "]");
PolySelectConvert 3;
string $closeVerts[] = ls -sl -fl -l
;
//Which vert is closest? -- simple distance check on each
string $closestVertName = "";
float $closestVertPos[2];
float $closestDistance = 1; //arbitrarily high number to ensure the first distance check succeeds
for ($modelVert in $closeVerts)
{
//Get position of modelVert
float $modelVertPos[] = `pointPosition -w $modelVert`;
//Distance to data point
float $x = ($modelVertPos[0] - $vertexInDataSplitFloat[0]);
float $y = ($modelVertPos[1] - $vertexInDataSplitFloat[1]);
float $z = ($modelVertPos[2] - $vertexInDataSplitFloat[2]);
float $testedDistance = sqrt (($x*$x) + ($y*$y) + ($z*$z));
if ($testedDistance < $vertMatchTolerance)
{
if ($testedDistance < $closestDistance)
{
$closestDistance = $testedDistance;
$closestVertName = $modelVert;
$closestVertPos = $modelVertPos;
}
//DEBUG
//print ("tested distance = " + $testedDistance + "n");
//print ("closest distance = " + $closestDistance + "n");
}
//DEBUG
//else
//print "---Failed tolerance test---n";
} //end for-in $closeVerts
///////////////////////////////
Hopefully it will be readable for you. I didn't bother changing var names and you can see I am also doing a distance tolerance check in there. Just ping me with any other questions you might have about it.
--JeffD