I have track several error in your script:
excuse my weak coding style…
import maya.OpenMaya as om
import maya.cmds as cmds
def get_mobject(node):
selectionList = om.MSelectionList()
selectionList.add(node)
oNode = om.MObject()
selectionList.getDependNode(0, oNode)
return oNode
vertexArray = om.MFloatPointArray()
uArray = om.MFloatArray()
vArray = om.MFloatArray()
numVertices = 1 #<-- this error you want you have 3 vertice in your triangle
numPolygons = 3 #<-- this error just swap the value : 1 poly
numVertices = 3
numPolygons = 1
vertices = [(0,0,0), (0,0,1.01), (0,1.12,1)]
uvs = [(0,0), (0,1), (1,1)]
conns = [1,2,3] #<-- another error vertex indices start at 0 in maya…
conns = [0,1,2]
pConnects = om.MIntArray()
for c in conns: pConnects.append©
pCounts = om.MIntArray()
for i in vertices: pCounts.append(3) #<-- another error in each poly we specify how many vertices here 3 but it can be more
pCounts = om.MIntArray()
for o in range(numPolygons):
pCounts.append(3)# one triagle so add 3 vertices
uvCounts = om.MIntArray()
uvIds = om.MIntArray()
for i in range(0, len(vertices)):
#Store the points
pt = om.MFloatPoint(vertices[i][0],vertices[i][1], vertices[i][2])
vertexArray.append(pt)
uArray.append(uvs[i][0])
vArray.append(uvs[i][1])
uvIds.append(i)
normally to fill uVcounts with only 1 UV set , the faceVertId are the same as face vert connection array : here 3 vertices/UV
uvCounts = pCounts
#Now create the mesh
#build components
mesh = om.MFnMesh()
ShapeMesh = cmds.group(em=True) # <-- we create an empty group/ trnasform node that will receive the mesh node as a sibling
parentOwner = get_mobject( ShapeMesh )
meshMObj = mesh.create(numVertices, numPolygons, vertexArray, pCounts, pConnects, uArray, vArray ,parentOwner ) #<-- don’t forget to add a parent owner
cmds.sets( ‘null1’, e=True,forceElement=‘initialShadingGroup’) # <–assign the defaut lambert shader
defaultUVSetName = ‘’
defaultUVSetName = mesh.currentUVSetName(-1)
mesh.assignUVs( uvCounts,uvIds, defaultUVSetName) #< even if uv a created you must assign them