Getting UV data...

Hey,

How would I go about getting the UV vertex data for a mesh? Basically, I want to make a little script that helps me with UVmapping, particularly merging vertices within the UV/Image Editor.

Is it possible to get that data? If so…how do I do it :smiley:

Thanks in advance,
Greenlig

Here is a script to print all of the UV coordinates in an object. I think that it should be pretty self explanatory.

import bpy

mesh = bpy.data.meshes['MeshName']

for face in mesh.faces:
    print "Face"
    
    for i in xrange(0, len(face.verts)):
        print "X: ", face.uv[i][0], "Y: ", face.uv[i][1]

Hey thanks Dergemkr.

Is there any way to find out which ones are selected within the UV mapping window?

Greenlig

Here, this is just an addition to the previous script.

import bpy

mesh = bpy.data.meshes['Cube']

for face in mesh.faces:
    print "Face"
    if(mesh.faceUV): # Test if the face is textured.
        for i in xrange(0, len(face.verts)):
            print "X: ", face.uv[i][0], "Y: ", face.uv[i][1]
            if face.uvSel[i] == 1: # if it is one, then it is selected
                print "Selected"
            else:
                print "Not Selected"

One thing that I noticed is that the status of selected or not is not recognized until the main window where the object is being edited is turned from edit mode back to object mode. Maybe this is a problem from them getting rid of UV Face Select mode, or possibly there is a way to update the data that I do not know about. One solution could be to switch back to object mode in the script and then after you are done with the data, switch back to edit mode.

dergemkr