Search code examples
pythonmayamaya-api

Maya API add/remove vertices/edges from existing mesh


Is there a way to add/remove vertices, edges and faces from existing meshes with Python API? I found a few question around the web about this, but all without answer.


Solution

  • In OpenMaya.MFnMesh there are some methods for this:

    • To delete:
      • deleteEdge(edgeId, modifier=None) -> self
      • deleteFace(faceId, modifier=None) -> self
      • deleteVertex(vertexId, modifier=None) -> self
    • To add:
      • addPolygon(vertices, mergeVertices=True, pointTolerance=kPointTolerance, loopCounts=None) -> faceId; Which merges vertices within a certain range (pointTolerance).

    So it seems like you cannot just create single vertices and then properly connect them with edges and faces, but you have to define a complete polygon.

    If there are other solutions I would be happy to know!