Fix error handling

This commit is contained in:
989onan
2024-09-10 12:25:10 -04:00
parent 94dcc3ed7a
commit 6954342d37
+17 -11
View File
@@ -35,6 +35,8 @@ class AvatarToolkit_OT_AlignUVEdgesToTarget(Operator):
return False return False
if not context.space_data.show_uvedit: if not context.space_data.show_uvedit:
return False return False
if context.scene.tool_settings.use_uv_select_sync:
return False
return True return True
def execute(self, context: Context): def execute(self, context: Context):
@@ -84,7 +86,7 @@ class AvatarToolkit_OT_AlignUVEdgesToTarget(Operator):
#hmmm real stupid grimlin hours with this one. Using a string as the index of a dictionary of loop corners that end up on the same coordinate #hmmm real stupid grimlin hours with this one. Using a string as the index of a dictionary of loop corners that end up on the same coordinate
for k,i in enumerate(uv_lay.vertex_selection): #go through the selected vertices on object. for k,i in enumerate(uv_lay.vertex_selection): #go through the selected vertices on object.
if (i.value == True) and (bm.verts[me.loops[k].vertex_index].select == True) and (bm.verts[me.loops[k].vertex_index].hide == False): #find vertices that are not hidden and are are selected again TODO: Why does checking hidden not work? - @989onan if (i.value == True) and (bm.verts[me.loops[k].vertex_index].select == True) and (bm.verts[me.loops[k].vertex_index].hide == False): #filter out vertices that are hidden from UV port
key = np.array(uv_lay.uv[k].vector[:]) key = np.array(uv_lay.uv[k].vector[:])
key = key.round(decimals=5) #make a key that is the position of a selected vertex key = key.round(decimals=5) #make a key that is the position of a selected vertex
@@ -94,7 +96,7 @@ class AvatarToolkit_OT_AlignUVEdgesToTarget(Operator):
vert_target_verts[str(key)] = me.loops[k].vertex_index #associate the index of the physical vertex in real space with the coordinate of the uv vertices that share a position (Basically associate UV vert with real vert) vert_target_verts[str(key)] = me.loops[k].vertex_index #associate the index of the physical vertex in real space with the coordinate of the uv vertices that share a position (Basically associate UV vert with real vert)
if len(vert_target_loops) > 4000: #This usually indicates that the user has a bunch of crap selected. if len(vert_target_loops) > 4000: #This usually indicates that the user has a bunch of crap selected.
self.report({'WARNING'}, t("UVTools.align_uv_to_target.warning.too_much")) self.report({'WARNING'}, t("UVTools.align_uv_to_target.warning.too_much"))
return {'FINISHED'} return
print("Finding connections on line for \""+obj_name+"\"!") print("Finding connections on line for \""+obj_name+"\"!")
me.validate() me.validate()
@@ -174,7 +176,7 @@ class AvatarToolkit_OT_AlignUVEdgesToTarget(Operator):
if len(startpoints) != 2: if len(startpoints) != 2:
self.report({'WARNING'}, t("UVTools.align_uv_to_target.warning.need_a_line").format(obj=obj_name)) self.report({'WARNING'}, t("UVTools.align_uv_to_target.warning.need_a_line").format(obj=obj_name))
return {'FINISHED'} return
a_list1 = startpoints[0].replace(", "," ").replace("[","").replace("]","").split() a_list1 = startpoints[0].replace(", "," ").replace("[","").replace("]","").split()
map_object1 = map(float, a_list1) map_object1 = map(float, a_list1)
@@ -231,14 +233,18 @@ class AvatarToolkit_OT_AlignUVEdgesToTarget(Operator):
continue continue
#create our list of points that is a chain. then sort the chain into the correct order based on connections of vertices and the faces that the vertices make up in the UV map. #create our list of points that is a chain. then sort the chain into the correct order based on connections of vertices and the faces that the vertices make up in the UV map.
source_data = generate_loop_tree(source) try:
sorted_source_tree = sort_uv_tree(source_data["tree"], source) source_data = generate_loop_tree(source)
print("Sorted source "+source) sorted_source_tree = sort_uv_tree(source_data["tree"], source)
print(sorted_source_tree) print("Sorted source "+source)
print(sorted_source_tree)
vertex_factor = float(len(sorted_target_tree)-1) / (float(len(sorted_source_tree)-1))
vertex_factor = float(len(sorted_target_tree)-1) / (float(len(sorted_source_tree)-1))
print(str(vertex_factor)+" = "+str(float(len(sorted_target_tree)-1)) + " / " + str((float(len(sorted_source_tree)-1)))+")")
print(str(vertex_factor)+" = "+str(float(len(sorted_target_tree)-1)) + " / " + str((float(len(sorted_source_tree)-1)))+")")
except Exception as e:
print(e)
return {'FINISHED'}
for k,i in enumerate(sorted_source_tree): for k,i in enumerate(sorted_source_tree):