3
$\begingroup$

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

$\endgroup$
0

1 Answer 1

4
$\begingroup$

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)
$\endgroup$
4
  • $\begingroup$ Sorry, but how could I change the values? Not only see them? $\endgroup$
    – CuriousElf
    Commented Dec 15, 2014 at 22:06
  • $\begingroup$ like this: vert[uv_layer].uv.x = 0.5 ,and the same for y $\endgroup$ Commented Dec 16, 2014 at 10:23
  • $\begingroup$ Not working... I`ve tried some changes in this code, but nothing seems to work. $\endgroup$
    – CuriousElf
    Commented Dec 18, 2014 at 18:15
  • $\begingroup$ I`ve edited the question, maybe it helps $\endgroup$
    – CuriousElf
    Commented Dec 18, 2014 at 18:18

Not the answer you're looking for? Browse other questions tagged .