From 1e4e584297966cbe8519d3fbf4368389186c9060 Mon Sep 17 00:00:00 2001 From: scut Date: Tue, 11 Feb 2025 18:30:37 -0500 Subject: [PATCH 1/2] added warnings for when exporting all has exceptions for some objects --- fast64_internal/sm64/sm64_objects.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/fast64_internal/sm64/sm64_objects.py b/fast64_internal/sm64/sm64_objects.py index 5a9470c08..1f720b830 100644 --- a/fast64_internal/sm64/sm64_objects.py +++ b/fast64_internal/sm64/sm64_objects.py @@ -1,5 +1,6 @@ import math, bpy, mathutils import os +import traceback from bpy.utils import register_class, unregister_class from re import findall, sub from pathlib import Path @@ -1552,6 +1553,7 @@ def draw(self, layout, index): class SM64_ExportCombinedObject(ObjectDataExporter): bl_idname = "object.sm64_export_combined_object" bl_label = "SM64 Combined Object" + _failed_exports = set() def write_file_lines(self, path, file_lines): with open(path, "w") as file: @@ -1865,6 +1867,9 @@ def execute_col(self, props, obj): # pass on multiple export, throw on singular if not props.export_all_selected: raise Exception(exc) from exc + else: + traceback.print_exc() + self._failed_exports.add(obj.name) # writes model.inc.c, geo.inc.c file, geo_header.h # writes include into aggregate file (leveldata.c/.c & geo.c) @@ -1887,8 +1892,12 @@ def execute_gfx(self, props, context, obj, index): # pass on multiple export, throw on singular if not props.export_all_selected: raise Exception(e) + else: + traceback.print_exc() + self._failed_exports.add(obj.name) def execute(self, context): + self._failed_exports = set() props = context.scene.fast64.sm64.combined_export try: self.verify_context(context, props) @@ -1907,8 +1916,16 @@ def execute(self, context): return {"CANCELLED"} props.context_obj = None - # you've done it!~ - self.report({"INFO"}, "Success!") + if self._failed_exports: + # if you export all and missed some stuff, tell the user + self.report( + {"WARNING"}, + f"Objects {', '.join(self._failed_exports)} exported with errors, view console log for details.", + ) + else: + # you've done it!~ + self.report({"INFO"}, "Success!") + return {"FINISHED"} From bb56b1e01b10c9c46f1d6afaa7ef3277277f14f5 Mon Sep 17 00:00:00 2001 From: scut Date: Tue, 11 Feb 2025 19:00:07 -0500 Subject: [PATCH 2/2] changed code to instead generate exceptions except for specific ones which will give a warning in the console. Possibility to add warning for user for other exceptions though probably not --- fast64_internal/sm64/sm64_collision.py | 2 +- fast64_internal/sm64/sm64_geolayout_writer.py | 2 +- fast64_internal/sm64/sm64_objects.py | 27 +++++-------------- fast64_internal/utility.py | 17 +++++++++++- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/fast64_internal/sm64/sm64_collision.py b/fast64_internal/sm64/sm64_collision.py index 6e2907f0c..bb3b59c72 100644 --- a/fast64_internal/sm64/sm64_collision.py +++ b/fast64_internal/sm64/sm64_collision.py @@ -387,7 +387,7 @@ def exportCollisionCommon(obj, transformMatrix, includeSpecials, includeChildren try: addCollisionTriangles(tempObj, collisionDict, includeChildren, transformMatrix, areaIndex) if not collisionDict: - raise PluginError("No collision data to export") + raise PluginError("No collision data to export", PluginError.exc_warn) cleanupDuplicatedObjects(allObjs) obj.select_set(True) bpy.context.view_layer.objects.active = obj diff --git a/fast64_internal/sm64/sm64_geolayout_writer.py b/fast64_internal/sm64/sm64_geolayout_writer.py index fbe779a97..0fd07e697 100644 --- a/fast64_internal/sm64/sm64_geolayout_writer.py +++ b/fast64_internal/sm64/sm64_geolayout_writer.py @@ -504,7 +504,7 @@ def convertObjectToGeolayout( convertTextureData, ) if is_actor and not meshGeolayout.has_data(): - raise PluginError("No gfx data to export, gfx export cancelled") + raise PluginError("No gfx data to export, gfx export cancelled", PluginError.exc_warn) except Exception as e: raise Exception(str(e)) finally: diff --git a/fast64_internal/sm64/sm64_objects.py b/fast64_internal/sm64/sm64_objects.py index 1f720b830..dfdade5f1 100644 --- a/fast64_internal/sm64/sm64_objects.py +++ b/fast64_internal/sm64/sm64_objects.py @@ -1553,7 +1553,6 @@ def draw(self, layout, index): class SM64_ExportCombinedObject(ObjectDataExporter): bl_idname = "object.sm64_export_combined_object" bl_label = "SM64 Combined Object" - _failed_exports = set() def write_file_lines(self, path, file_lines): with open(path, "w") as file: @@ -1865,11 +1864,8 @@ def execute_col(self, props, obj): bpy.ops.object.sm64_export_collision(export_obj=obj.name) except Exception as exc: # pass on multiple export, throw on singular - if not props.export_all_selected: + if not props.export_all_selected or not PluginError.check_exc_warn(exc): raise Exception(exc) from exc - else: - traceback.print_exc() - self._failed_exports.add(obj.name) # writes model.inc.c, geo.inc.c file, geo_header.h # writes include into aggregate file (leveldata.c/.c & geo.c) @@ -1888,16 +1884,12 @@ def execute_gfx(self, props, context, obj, index): if props.export_script_loads and props.model_id != 0: self.export_model_id(context, props, index) self.export_script_load(context, props) - except Exception as e: + except Exception as exc: # pass on multiple export, throw on singular - if not props.export_all_selected: - raise Exception(e) - else: - traceback.print_exc() - self._failed_exports.add(obj.name) + if not props.export_all_selected or not PluginError.check_exc_warn(exc): + raise Exception(exc) def execute(self, context): - self._failed_exports = set() props = context.scene.fast64.sm64.combined_export try: self.verify_context(context, props) @@ -1916,15 +1908,8 @@ def execute(self, context): return {"CANCELLED"} props.context_obj = None - if self._failed_exports: - # if you export all and missed some stuff, tell the user - self.report( - {"WARNING"}, - f"Objects {', '.join(self._failed_exports)} exported with errors, view console log for details.", - ) - else: - # you've done it!~ - self.report({"INFO"}, "Success!") + # you've done it!~ + self.report({"INFO"}, "Success!") return {"FINISHED"} diff --git a/fast64_internal/utility.py b/fast64_internal/utility.py index 4c19b0b10..0f5e8f64a 100644 --- a/fast64_internal/utility.py +++ b/fast64_internal/utility.py @@ -10,7 +10,22 @@ class PluginError(Exception): - pass + # arguments for exception processing + exc_halt = "exc_halt" + exc_warn = "exc_warn" + + """ + because exceptions generally go through multiple funcs + and layers, the easiest way to check if we have an exception + of a certain type is to check for our input string + """ + + @classmethod + def check_exc_warn(self, exc): + for arg in exc.args: + if type(arg) is str and self.exc_warn in arg: + return True + return False class VertexWeightError(PluginError):