How to select uv faces using python? I have a cuboidal structure. I have it uv unwrapped. Now, I need to apply a same seamless texture to all the sides. In effect, I need the uv faces one over the other. The code snippet below shows my approach in selecting the faces and placing them over each other,

bpy.context.area.type = 'IMAGE_EDITOR'
//Translating the faces, to place them one above the other
bpy.ops.uv.select(extend=False, location=(0.0, 0.0))
bpy.ops.transform.translate(value=(0.378906, 0, 0)) 

bpy.ops.uv.select(extend=False, location=(0.25, 0.0))
bpy.ops.transform.translate(value=(0.135343, 0, 0))

bpy.ops.uv.select(extend=False, location=(0.75, 0.0))
bpy.ops.transform.translate(value=(-0.351892, 0, 0))

bpy.ops.uv.select(extend=False, location=(0.6, 0.0))
bpy.ops.transform.translate(value=(-0.108398, 0, 0))    


While I achieved as much as that, the next step requires me to scale them, so as to apply the image texture properly. So, once again I started selecting the same faces using the same method above. The only change was that "extend" was set to "true", in order to extend the selection. Well, simple as it felt, it didn't work. Then I realized, it selects based on the location and now all the faces have been translated to the same location.

It meant, I can't use this same selection statement. But this is the only method I know and I am still new to blender python.

My question. Is there an effective and easier way to select the uv faces, say like faces[0]? If so, please share. 

New Edit:

Now this is the sequence of operations which I executed in the console,

&gt;&gt;&gt; import bmesh
&gt;&gt;&gt; bm = bmesh.new()
&gt;&gt;&gt; obj = bpy.context.active_object
&gt;&gt;&gt; bm.from_mesh(obj) 
&gt;&gt;&gt; bm.faces.
             active
             ensure_lookup_table(
             get(
             index_update(
             layers
             new(
             remove(
             sort(


As you can see, bm.faces does not have any attribute named loop.
Manipulating the UV coordinates of a face is usually done via the bmesh API.  Here is an example extracted from http://web.purplefrog.com/~thoth/blender/python-cookbook/barber-pole.html

def spiralUVs(mesh, xPlus):
    # add a UV layer called "spiral" and make it slanted.
    mesh.uv_textures.new("spiral")
    bm = bmesh.new()
    bm.from_mesh(mesh)

    bm.faces.ensure_lookup_table()

    uv_layer = bm.loops.layers.uv[0]

    nFaces = len(bm.faces)
    for fi in range(nFaces):
        x0 = fi*2/nFaces
        x1 = (fi+1)*2/nFaces
        # assume a quad; 0..3
        bm.faces[fi].loops[0][uv_layer].uv = (x0, 0)
        bm.faces[fi].loops[1][uv_layer].uv = (x1, 0)
        bm.faces[fi].loops[2][uv_layer].uv = (xPlus+x1, 1)
        bm.faces[fi].loops[3][uv_layer].uv = (xPlus+x0, 1)
    bm.to_mesh(mesh)


Other examples that manipulate UV maps include http://web.purplefrog.com/~thoth/blender/python-cookbook/expand-uv-to-fit.html and http://web.purplefrog.com/~thoth/blender/python-cookbook/uv-from-geometry-cubic.html