Hey guys, I’m trying to learn the Maya Python API, my first attempt is to create two functions to get and set vertex positions on a mesh.
I’ve managed to get the positions and output them to a list, but what I havent figured out is how I can pass that list to another function to set the positions. I think my problem is that I don’t know how to append my list over to an MPointArray, I’ve googled a lot but I can’t figure out how to do this
Here’s my code:
http://pastebin.com/mp16Pd8r
#GET VERTEX/CV POSITIONS
def getGeoPointPosition(geoObj, space='worldSpace'):
#Create an empty objects/variables to store positions, functionSet and space
mPoint = OpenMaya.MPointArray()
mSpace = None
pointPos = []
#Get which space it should return the positions in (localSpace/worldSpace)
if space == 'localSpace': mSpace = OpenMaya.MSpace.kObject
elif space: == 'worldSpace': mSpace = OpenMaya.MSpace.kWorld
#Attach a MFnMesh functionSet and get the positions
mFnSet = OpenMaya.MFnMesh(getDagPath(geoObj[0]))
mFnSet.getPoints(mPoint, mSpace)
#For each vertex/CV of the object
for x in range(0, mPoint.length()):
#Append the current vertex position to the list
pointPos.append([mPoint[x][0], mPoint[x][1], mPoint[x][2]])
#Return the positions
return pointPos
#----------------------------------------------------------------------------------------
#SET VERTEX/CV POSITIONS
def setGeoPointPos(geoObj, positions=[], space='worldSpace'):
#Create an empty objects/variables to store positions, functionSet and space
mPoint = OpenMaya.MPointArray()
mSpace = None
#Add the list to the MPointArray
mPoint.append(positions)
#Get which space it should return the positions in (localSpace/worldSpace)
if space == 'localSpace': mSpace = OpenMaya.MSpace.kObject
elif space: == 'worldSpace': mSpace = OpenMaya.MSpace.kWorld
#Attach a MFnMesh functionSet and set the positions
mFnSet = OpenMaya.MFnMesh(getDagPath(geoObj[0]))
mFnSet.getPoints(mPoint, mSpace)
#Return the positions
return pointPos
Any tips/hints would be appreciated!