I'm trying to create a tool in maya that checks if the uv shells are overlapping and it's turning out to be a bit of a challege. So far Ive managed to get the vertex ID's of a mesh but I've struggled to get the corresponding uv ids. At the moment I have this code but the u and v variables print as none and I cant understand why that is? Any ideas on how I can get the uv ids of a mesh?
This is the code I have:
def check_overlapping_uvs(self, dag_path, grid_resolution=10):
# Find UV set name
uv_set_name = cmds.polyUVSet(dag_path.fullPathName(), currentUVSet=True, query=True)
print(uv_set_name)
# Convert UV set name to UV selection
num_vertices = cmds.polyListComponentConversion(dag_path.fullPathName(), fromUV=True, toVertex=True)
print(num_vertices)
vertices = cmds.ls(num_vertices, flatten=True)
print(vertices)
# Get the UVs of the mesh
u_array = []
v_array = []
for vertex in vertices:
# Retrieve the UV values for each vertex
u = cmds.polyEditUV(vertex, uValue=True, uvs=uv_set_name)
v = cmds.polyEditUV(vertex, vValue=True, uvs=uv_set_name)
print(u, v)
# u_array.append(u[0])
# v_array.append(v[1])
To note the selected mesh is coming from a seperate function which the code is here for reference:
for geo in selected_geo:
print(selected_geo)
if self.stop_validation_flag:
break
shape_nodes = cmds.listRelatives(geo, shapes=True)
if shape_nodes:
shape_node = shape_nodes[0]
selection_list = om.MSelectionList()
selection_list.add(shape_node)
dag_path = om.MDagPath()
selection_list.getDagPath(0, dag_path)
uv_check = self.check_overlapping_uvs(dag_path)