I want to select a vertex on UV layer.

Question 1 ]

I did UV Unwrap.

And i did select a some vertices on mesh at 3D-view editor.
And i run script a such as below.

But why not selected a vertex on uv layer?

import bpyme = bpy.context.object.data
uv_layer = me.uv_layers.active.data
bpy.ops.uv.select_all(action=‘DESELECT’)
bpy.ops.object.mode_set(mode=“OBJECT”)
for face in me.polygons:
for li in face.loop_indices:
vi = me.loops[li].vertex_index
if me.vertices[vi].select == True:
uv_layer[li].select = True
print("li : " , li , "vi : " , vi , "uv : " ,uv_layer[li].uv)
for ar in bpy.context.screen.areas:
ar.tag_redraw()

bpy.ops.object.mode_set(mode=“EDIT”)


Question 2]

Bmesh had select_history property.
Maybe Does Uv_layers have select_history property?

Please answer to me.
Thank you.

You need to select the uv layer loops:

for li in face.loop_indices:
     me.uv_layers.active.data[li].select = True

There’s also a .select_edge property.

You may be interested into bpy.context.tool_settings.use_uv_select_sync,
set it to True and any selection changes made to me.vertices should be reflected to UV verts/edges.

Note that access to UV layer data isn’t possible in editmode with standard API, you can use the bmesh module and the uv custom layer (bm.loops.layers.uv).

There’s no select_history for UV elements, but if sync is on, you can use the one for mesh elements.

What if I want to reverse the process? is to say select a vertex in UV and is selected automatically in 3DView??

sorry for bad english I don’t know how to say that correctly … here in spanish:

“¿que pasa si yo quiero el proceso inverso? es decir seleccionar un vertice en UV y que se seleccione automaticamente en el 3dview”

Thank you your reply.
And I feel good know more knowledge.

What if I want to reverse the process?

The propagation is bi-directional in UI, but if I set the UVs to selected, nothing happens (also not if you enable the UV sync afterwards).

You have more luck with the bmesh module:

import bpy
import bmesh

me = bpy.context.object.data
bm = bmesh.from_edit_mesh(me)

bpy.context.tool_settings.use_uv_select_sync = False
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.uv.select_all(action='DESELECT')

uv_layer = bm.loops.layers.uv.active

face = bm.faces[1]
for loop in face.loops:
    loop[uv_layer].select = True
    loop[uv_layer].select_edge = True
    loop.vert.select = True
    
bm.select_flush(True)

bmesh.update_edit_mesh(me, False, False)

WOOOOWWW!! this open me a lot of ideas in my head!!!.. your genius!!!

then inf propagation is bi-directional we can think that for example we can cut the UVs and update the 3dview …right?? that’s cool!!!

do you know some references to learn about this? official repo are out of date and I don’t know where find info about this kind of thinks

thanks

Diego

The mesh takes precedence over the UVs - if you enable sync, mesh selection is flushed to UV selection and there’s no way to invert this behavior. If you make UV selections with sync on in the UI, the changes are flushed to mesh selection however. This is not the case for the API (neither standard API nor bmesh module, it needs to be manually set on both).

There are actually no resources to learn such things. I talked to a developer on IRC about the syncing, that’s why I know something about it. You may find some hints in the source code of Blender, but otherwise it’s ideasman’s work and he should know what works how with the python API.