How to retrieve the selected uvs in UV/Image editor ?


How to retrieve the selected uvs in UV/Image editor ?
I am looking for a function that returns the faces (or the vertices) that are selected by the user in UV/Image editor.
This selection can be different from the geometric selection…

Thanks for your help.

I use this:

def selectedUVs(mesh, uvlayer=None, sync=False):
	'''Get the vertices visible and selected in the UV view.'''
	uvlayer = uvlayer or
	uvs = {}
	for f, uv in zip(mesh.loops,
		if mesh.vertices[f.vertex_index].select and (sync or
			uvs[f.vertex_index] = uv.uv
	return uvs

A typical call might be:

 selected = selectedUVs(, sync=context.scene.tool_settings.use_uv_select_sync)

Best wishes,

Thank you very much Matthew for your answer.
You help me a lot and you give me a perfect code snippet.

I also searched the equivalent solution for bmesh and I found this:
This code snippet scans the faces, the vertices and corresponding uvs.

import bpy, bmesh

for currentFace in bm.faces:
    print("Face index=%s selected=%s" % (currentFace.index,
        for currentVertex,idx in zip(currentFace.verts,range(len(currentFace.verts))):
            print("	Vertex index=%s pos=%s selected=%s" % (currentVertex.index,,
            print("	UV pos=%s selected=%s" % (currentFace.loops[idx][uv_layer].uv,currentFace.loops[idx][uv_layer].select))

I hope that I don’t commit a mistake with the use of the index idx in the loop (currentFace.loops[idx][uv_layer].select).
I presume that the vertex order in a face (currentFace.verts) is the same than in the loop.
But I’m not entirely sure of that…

Thanks again