Python - move UV for selected items I want to use python to move the UVs of the selected objects. I am having trouble with moving the UVs. When I run my script I moves the objects instead, not the UVs. All object have exactly 1 UV map. 

My approach the problem:

for mesh in selection:


for UVs in mesh


select all UVs


move UVs




Here is my code.

import bpy

scene = bpy.context.scene
for count, ob in enumerate(bpy.context.selected_objects):
    if ob.type == 'MESH':
        scene.objects.active = ob
        bpy.ops.object.mode_set(mode='EDIT', toggle=False)

        bpy.ops.mesh.reveal()
        bpy.ops.mesh.select_all(action='SELECT')

        # execute any editmode tool
        move_x = count % 10
        move_y = count // 10
        bpy.ops.transform.translate(value=(move_x, move_y, 0), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=0.263331)


        bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
It's all about context, at no point are you in the image editor. The same bpy.ops.transform.translate() is used in the 3d view and the image editor. Basically, you could just save the current area, switch to the editor, perform transforms and switch back. Granted, there are much more elegant ways to do this but for a 3 line hack, it works quite well.

import bpy

#+ grab the current area
original_area = bpy.context.area.type

scene = bpy.context.scene
for count, ob in enumerate(bpy.context.selected_objects):
    if ob.type == 'MESH':
        scene.objects.active = ob
        #+ switch to the image editor to perform transforms etc
        bpy.context.area.type = 'IMAGE_EDITOR'
        bpy.ops.object.mode_set(mode='EDIT', toggle=False)

        bpy.ops.mesh.reveal()
        bpy.ops.mesh.select_all(action='SELECT')
        #+ select the uvs
        bpy.ops.uv.select_all(action='SELECT')

        bpy.ops.transform.translate(value=(0.125, 0, 0), constraint_axis=(True, False, False))

        #+ return to the original mode where the script was run
        bpy.context.area.type = original_area
        bpy.ops.object.mode_set(mode='OBJECT', toggle=False)