View Full Version : Python Help! - Get UVs from Face

10 October 2008, 06:45 PM
I need to be able to find out what uvs are associated with a face, but in python. Any ideas anyone?

10 October 2008, 09:57 PM
I came across something similar to this recently. I worked in MEL but the commands I used are also available in python.

for each face get a list of vertexFaces (getAttr <obj>.vtxFace
then convert those vtxFaces into UVs using polyListComponentConversion.

you will have to look at the documentation for hte polyListComponentConversion command because I dont know the python syntax off the top of my head. you could use polyListComponentConversion to convert the face into vtxFaces but its faster just to use the getAttr. knowing python can have multi-dimensional arrays it might even be better to getAttr on all the vtxFaces at once.

I wish I knew more about the maya open API because I am betting theres a faster method you could use but I know the above works and keeps the UVs in the proper order.

10 October 2008, 07:00 PM
This should do the trick...

import maya.cmds as mc

#store original selection
saSel =
print 'Selection: ' + saSel[0]

#get faces from selected object[0], toFace=1), r=1)
saFaces =,fl=1)

#iterate through the faces and print out the uv's with them
for sFace in saFaces:
print ' FACE: ' + sFace, toUV=1), r=1)
saUVs =, fl=1)
for sUV in saUVs:
print ' UV: '+ sUV

10 October 2008, 10:23 PM
Awesome, thanks so much for the helps guys, Ill give it a shot.

CGTalk Moderation
10 October 2008, 10:23 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.