2

I want to access to this data:

uv vertice and 2d cursor coordinates example

I tried:

Exporting UV coordinates

http://blenderartists.org/forum/showthread.php?254004-Accessing-UV-data-in-Python-script

http://blenderartists.org/forum/showthread.php?334400-I-want-to-select-a-vertex-on-UV-layer

but all that return the 3dview vertices coordinates....

some ideas?

thanks

yhoyo
  • 2,285
  • 13
  • 32

1 Answers1

2

This will print the uv coordinates of each vertex and (x, y) position in the UVmap editor then the cursor location

import bpy

ob = bpy.context.active_object

for area in bpy.context.screen.areas:
    if area.type == 'IMAGE_EDITOR':   #find the UVeditor
        cursor = area.spaces.active.cursor_location   # get cursor location
        if  area.spaces.active.image :                #get image dimension
            x = area.spaces.active.image.size[0]
            y = area.spaces.active.image.size[1]
        else:
            x = y = 256

        for v in ob.data.loops :
             uv = ob.data.uv_layers.active.data[v.index].uv   #get uv coo

            #calculate and print the position in the uv editor
             print("vertex %d at with UV coo (%d , %d) at  (%d ,%d)"%(v.index, uv[0], uv[1], uv[0]*x, uv[1]*y) )  
             print( "is selected ? " , ob.data.uv_layers.active.data[v.index].select )

        print (cursor,x,y)
Chebhou
  • 19,533
  • 51
  • 98
  • hi.. uv = ob.data.uv_layers.active.data[v.index].uv don't work.. even in this case the v in ob.data.loops is the same as each vertex in UV area yes??? – yhoyo Apr 03 '15 at 23:15
  • @yhoyo what error you are getting exactly ? – Chebhou Apr 03 '15 at 23:35
  • this one: http://prntscr.com/6p93yx – yhoyo Apr 03 '15 at 23:50
  • @yhoyo it seems that it doesn't work in edit mode , i'll look for something else – Chebhou Apr 04 '15 at 00:49
  • I understand.. but this is confusing because this data in objecto_mode is practically pointless and switch between modes is not very efficient.. also.. "UV vertex" is only avalaible in edit_mode... some another ideas please? – yhoyo Apr 04 '15 at 01:00
  • i guess you already have the answer in BA forum you either change modes or use the bmesh – Chebhou Apr 04 '15 at 14:24