3

Well, I'm trying to change the values of UV Vertex (see the picture):

UV VERTEX

When I change the values, selected part of UV (orange selection) will move.

How I can do this change USING PYTHON?

My code untill now...

import bpy
import bmesh

(...)    

for area in bpy.context.screen.areas:
    area.type == 'VIEW_3D'
bpy.ops.object.editmode_toggle()

#+ grab the current area
original_area = 'IMAGE_EDITOR'

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
        for area in bpy.context.screen.areas:
            area.type == 'IMAGE_EDITOR'
            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
            for area in bpy.context.screen.areas:
                area.type == 'IMAGE_EDITOR'
            bpy.ops.object.mode_set(mode='OBJECT', toggle=False)

Still moving the object. Tks

CuriousElf
  • 277
  • 2
  • 9

1 Answers1

4

You access the UV coords by looping over face loops.

import bpy
import bmesh

#retrieve mesh in object mode
if bpy.context.active_object.mode!='OBJECT'
    bpy.ops.object.mode_set(mode='OBJECT')
mesh = bpy.context.object.data
bm = bmesh.new()
bm.from_mesh(mesh)
uv_layer = bm.loops.layers.uv.active

for face in bm.faces:
    for vert in face.loops:
        # here are the UV coords
        print(vert[uv_layer].uv)

#write the mesh back if you changed the uvs
bm.to_mesh(mesh)
Jaroslav Jerryno Novotny
  • 51,077
  • 7
  • 129
  • 218