diff --git a/functions/join_meshes.py b/functions/join_meshes.py index 3310ae9..6a4e3d2 100644 --- a/functions/join_meshes.py +++ b/functions/join_meshes.py @@ -18,32 +18,46 @@ class JoinAllMeshes(Operator): return armature is not None and is_valid_armature(armature) def execute(self, context: Context) -> Set[str]: - self.join_all_meshes(context) - return {'FINISHED'} + try: + self.join_all_meshes(context) + return {'FINISHED'} + except Exception as e: + self.report({'ERROR'}, f"{t('Optimization.join_error')}: {str(e)}") + return {'CANCELLED'} def join_all_meshes(self, context: Context) -> None: if not select_current_armature(context): - self.report({'WARNING'}, t("Optimization.no_armature_selected")) - return + raise ValueError(t("Optimization.no_armature_selected")) armature = get_selected_armature(context) bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.select_all(action='DESELECT') meshes: List[Object] = get_all_meshes(context) + if not meshes: + raise ValueError(t("Optimization.no_meshes_found")) + for mesh in meshes: mesh.select_set(True) if bpy.context.selected_objects: bpy.context.view_layer.objects.active = bpy.context.selected_objects[0] - bpy.ops.object.join() - bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) + try: + bpy.ops.object.join() + except RuntimeError as e: + raise RuntimeError(f"{t('Optimization.join_operation_failed')}: {str(e)}") + + try: + bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) + except RuntimeError as e: + raise RuntimeError(f"{t('Optimization.transform_apply_failed')}: {str(e)}") + fix_uv_coordinates(context) bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.select_all(action='DESELECT') self.report({'INFO'}, t("Optimization.meshes_joined")) else: - self.report({'WARNING'}, t("Optimization.no_mesh_selected")) + raise ValueError(t("Optimization.no_mesh_selected")) context.view_layer.objects.active = armature @@ -59,15 +73,18 @@ class JoinSelectedMeshes(Operator): return context.mode == 'OBJECT' and len([obj for obj in context.selected_objects if obj.type == 'MESH']) > 1 def execute(self, context: Context) -> Set[str]: - self.join_selected_meshes(context) - return {'FINISHED'} + try: + self.join_selected_meshes(context) + return {'FINISHED'} + except Exception as e: + self.report({'ERROR'}, f"{t('Optimization.join_error')}: {str(e)}") + return {'CANCELLED'} def join_selected_meshes(self, context: Context) -> None: selected_objects: List[Object] = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH'] if len(selected_objects) < 2: - self.report({'WARNING'}, t("Optimization.select_at_least_two_meshes")) - return + raise ValueError(t("Optimization.select_at_least_two_meshes")) bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.select_all(action='DESELECT') @@ -77,11 +94,20 @@ class JoinSelectedMeshes(Operator): if bpy.context.selected_objects: bpy.context.view_layer.objects.active = bpy.context.selected_objects[0] - bpy.ops.object.join() - bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) + try: + bpy.ops.object.join() + except RuntimeError as e: + raise RuntimeError(f"{t('Optimization.join_operation_failed')}: {str(e)}") + + try: + bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) + except RuntimeError as e: + raise RuntimeError(f"{t('Optimization.transform_apply_failed')}: {str(e)}") + fix_uv_coordinates(context) bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.select_all(action='DESELECT') self.report({'INFO'}, t("Optimization.selected_meshes_joined")) else: - self.report({'WARNING'}, t("Optimization.no_mesh_selected")) + raise ValueError(t("Optimization.no_mesh_selected")) + diff --git a/resources/translations/en_US.json b/resources/translations/en_US.json index caf3aec..35b5095 100644 --- a/resources/translations/en_US.json +++ b/resources/translations/en_US.json @@ -53,6 +53,9 @@ "Optimization.remove_doubles_completed": "Remove doubles operation completed", "Optimization.select_armature": "Please select an armature", "Optimization.material_attribute_mismatch": "Attribute mismatch in material {material_name}, skipping", + "Optimization.join_error": "Error during mesh joining", + "Optimization.join_operation_failed": "Join operation failed", + "Optimization.transform_apply_failed": "Transform apply failed", "Tools.select_armature": "Please select an armature", "Tools.label": "Tools", "Tools.tools_title.label": "Tools:",