3
$\begingroup$

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)
$\endgroup$
  • $\begingroup$ May I ask why aren't you just getting the coordinates from the UV/Image Editor? $\endgroup$ – sekce Oct 14 '17 at 23:58
  • $\begingroup$ @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. $\endgroup$ – user47188 Oct 15 '17 at 0:42
2
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.