0
$\begingroup$

This is probably a pretty noob question but I'm trying to iterate through the uv edges of selected uv faces on an object to do operations like: bpy.ops.uv.align(axis="ALIGN_AUTO") I can't get any useful list that I can iterate through and for some reason I can't find anything on that. Would be great if someone can help a complete newby when it comes to blender's python API.

$\endgroup$
3
  • $\begingroup$ Welcome, could you please explain a bit more what you tried it? $\endgroup$
    – tetii
    Commented Dec 2, 2022 at 8:42
  • $\begingroup$ I do have a street layout with a lot of curved planes. When I unwrap the layout I get uvs where the faces are skewed to form the curve. My aim is to have a straight layout of the uvs for the curved streets to use a tileable street texture where the markings follow the curve. What I'm currently doing is select the edges of one uv face one by one and apply the ALIGN_AUTO command to make a perfect rectangle where each edge lays on an exact axis (u or v / xy). after that I select the face and apply the "Follow active quads" on it to make the uvs go in a straight line $\endgroup$
    – FynnGB
    Commented Dec 2, 2022 at 11:44
  • $\begingroup$ You can use or refer to an addon called UvSquares. $\endgroup$
    – tetii
    Commented Dec 3, 2022 at 8:29

1 Answer 1

0
$\begingroup$

In the Blender docs there is a code example that shows how faces and UV vertices are related.

This is a code snippet to print all the UV vertices of selected faces in the active mesh:

import bpy

# Force object mode, to ensure polygon selection is up to date
obj_mode = bpy.context.active_object.mode
if obj_mode != 'OBJECT':
    bpy.ops.object.mode_set(mode='OBJECT')

# Get active object
obj = bpy.context.object.data

# Get active uv map
uv_layer = obj.uv_layers.active.data

# Iterate all faces in the mesh
for polygon in obj.polygons:
    # Is this face selected?
    if polygon.select:
        # Print UV vertices of this face
        for loop_index in polygon.loop_indices:
            print(uv_layer[loop_index].uv)
print()

# Return to original mode
if obj_mode != 'OBJECT':
    bpy.ops.object.mode_set(mode=obj_mode)
$\endgroup$

You must log in to answer this question.

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