Sometime back, I was in need of getting the vertex position, through Maya API.
Then I have written the one, which suits my requirement. Here is the code:

#_ Import required modules
from maya.cmds import *
import maya.cmds as cmds
from maya.mel import *
import maya.mel as mel
from maya.OpenMaya import *
import maya.OpenMaya as om

def getMeshVtxPos(vtxName):
    #_ Get vertex number and object having that vertex
    testVtx =re.search('(?<=\[)(?P<vtxNum>[\d]+)(?=\])', str(vtxName))
    if testVtx:
        vtxNum =int(testVtx.group('vtxNum'))
        vtxObj =vtxName.split('.')[0]
    else:
        return

    #_ Get Api MDagPath for object
    activList =MSelectionList()
    activList.add(vtxObj)
    pathDg =MDagPath()
    activList.getDagPath(0, pathDg)

    #_ Iterate over all the mesh vertices and get position of required vtx
    mItVtx =MItMeshVertex(pathDg)
    vtxPos=[]
    while not mItVtx.isDone():
        if mItVtx.index() == vtxNum:
            point =MPoint()
            point =mItVtx.position(MSpace.kWorld)
            vtxPos =[round(point.x, 5), round(point.y, 5), round(point.z, 5)]
            break
        mItVtx.next()

    #_ Print or return your vtx position
    print [vtxPos]

#For Example
getMeshVtxPos('pSphere1.vtx[60]')

I think this small code may helps some of python n Maya api lovers :)

nJoy,
Subbu Addanki

Comment