Creating an MFloatPointArray from vert selection

Hello,

in maya api, how do you make a vert selection on a mesh and then store the selection in a MFloatPointArray?.

and also, is it possible to have a list of verts in an array that you have already created eg. vertList = [vert23,vert35,vert67 etc…] and then transform this list into an MFloatPointArray?

thanks alot guys,
Sam

api 1 or api 2?

1 i think

Sam

ok…was the answer 2?

Hello there. Here’s an answer to the first part of your question.

import maya.OpenMaya as om

selectionList = om.MSelectionList()
om.MGlobal.getActiveSelectionList(selectionList)

pointArray = om.MFloatPointArray()
for i in range(selectionList.length()):
    mdag = om.MDagPath()
    components = om.MObject()
    selectionList.getDagPath(i, mdag, components)
    if not components.hasFn(om.MFn.kMeshVertComponent):
        continue
    vtxIter = om.MItMeshVertex(mdag, components)
    while not vtxIter.isDone():
        pos = vtxIter.position()
        pointArray.append(om.MFloatPoint(pos))
        vtxIter.next()
print pointArray.length()

As to the second part of your question, I don’t have any code for you, but I can tell you that it is possible to take a list of verts and convert them to an MFloatPointArray.

thanks alot, this is very handy!

Sam