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

Hey,

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 mesh.uv_layers.active
	uvs = {}
	for f, uv in zip(mesh.loops, uvlayer.data):
		if mesh.vertices[f.vertex_index].select and (sync or uv.select):
			uvs[f.vertex_index] = uv.uv
	return uvs

A typical call might be:

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

Best wishes,
Matthew

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

bpy.ops.object.mode_set(mode='OBJECT')
obj=bpy.context.object
bm=bmesh.new()
bm.from_mesh(obj.data)
uv_layer=bm.loops.layers.uv.active
for currentFace in bm.faces:
    print("Face index=%s selected=%s" % (currentFace.index,currentFace.select))
    if currentFace.select:
        for currentVertex,idx in zip(currentFace.verts,range(len(currentFace.verts))):
            print("	Vertex index=%s pos=%s selected=%s" % (currentVertex.index,currentVertex.co,currentVertex.select))
            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
++