3

I'm trying to get the coordinates for the selected UV vertices with this script:

import bpy


mesh = bpy.context.object.data

uv = mesh.uv_layers.active.data

print(uv[0].uv)

But unfortunately the coordinates printed in the console are always the same regardless of what vertices I select.

enter image description here

Thanks in advance.


here is the code to get the coordinates for the selected vertices in the UV/Image editor :

import bpy
import bmesh

def main(context):
    obj = context.active_object
    me = obj.data
    bm = bmesh.from_edit_mesh(me)

    uv_layer = bm.loops.layers.uv.verify()
    bm.faces.layers.tex.verify()

    for f in bm.faces:
        for l in f.loops:
            luv = l[uv_layer]
            if luv.select:
                #print the coordinates
                print(luv.uv)

    bmesh.update_edit_mesh(me)
iKlsR
  • 43,379
  • 12
  • 156
  • 189
user47188
  • 75
  • 1
  • 7
  • May I ask why aren't you just getting the coordinates from the UV/Image Editor? – sekce Oct 14 '17 at 23:58
  • @sekce I want write a script that calculate the angle between the selected vertices(edge) and the x or y axis then align the island depending on the calculated angle, and in order to calculate the angle I need to get the coordinates of the vertices. – user47188 Oct 15 '17 at 00:42

1 Answers1

2

The example in your Blender will help you, see.
Text Editor > Templates > Python > Operator Mesh Uv

tetii
  • 1,775
  • 1
  • 9
  • 16