import maya.OpenMaya as om
import maya.cmds as mc
import maya.mel as mm
locPos = [[-0.05000000074505806, 0.0, 0.05000000074505806], [0.05000000074505806, 0.0, 0.05000000074505806], [0.05000000074505806, 1.0, 0.05000000074505806], [-0.05000000074505806, 1.0, 0.05000000074505806], [0.05000000074505806, 0.0, -0.05000000074505806], [-0.05000000074505806, 0.0, -0.05000000074505806], [0.05000000074505806, 1.0, -0.05000000074505806], [-0.05000000074505806, 1.0, -0.05000000074505806], [-0.125, 1.0, -0.125], [-0.125, 1.0, 0.125], [0.125, 1.0, 0.125], [0.125, 1.0, -0.125], [-0.0014583021402359009, 1.5859489440917969, -0.0014583021402359009], [0.0, 0.0, 0.0]]
#Create Single Face
#Get Vert as MPoint from loc position
vertices = []
for locP in locPos:
vertices.append(om.MFloatPoint(locP[0], locP[1], locP[2]))
#Create MFnmesh and its addPolygon command with a MPoint array for the face
meshFn = om.MFnMesh()
mergeVertices=True
pointTolerance = 0.001
faceArray = om.MFloatPointArray()
faceArray.setLength(4)
#setting array with the vert and its index
faceArray.set(vertices[0],0)
faceArray.set(vertices[1],1)
faceArray.set(vertices[2],2)
faceArray.set(vertices[3],3)
#All at once
numVertices = 14
numPolygons = 16
vertexFloatPointArray = om.MFloatPointArray()
for vertex in vertices:
vertexFloatPointArray.append(vertex)
count = [4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3]
polyCount = om.MIntArray()
for c in count:
polyCount.append(int(c))
connections = [0,1,2,3,1,4,6,2,4,5,7,6,5,0,3,7,3,2,10,9,2,6,11,10,6,7,8,11,7,3,9,8,9,10,12,10,11,12,11,8,12,8,9,12,0,13,1,1,13,4,4,13,5,5,13,0]
#note, making all the connection counter clockwise, to get normal pointing outwards
polyConnection = om.MIntArray()
for connection in connections:
polyConnection.append(int(connection))
meshFn.create(numVertices, numPolygons, vertexFloatPointArray, polyCount, polyConnection)