From 4593e5aea641f0afee40f5e141f6f0a4475f1afc Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 31 Mar 2025 12:34:02 +0500 Subject: [PATCH] Fix ExportHelper not optional filename_ext #6463 (4594f59) --- .../bonsai/bim/module/brick/operator.py | 2 ++ .../bonsai/bim/module/clash/operator.py | 5 +++ src/bonsai/bonsai/bim/module/csv/operator.py | 3 ++ .../bonsai/bim/module/debug/operator.py | 1 + src/bonsai/bonsai/bim/module/fm/operator.py | 32 ++++++++++++------- .../bonsai/bim/module/light/operator.py | 1 + 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/brick/operator.py b/src/bonsai/bonsai/bim/module/brick/operator.py index bb4f5f3277..94a9f9fe54 100644 --- a/src/bonsai/bonsai/bim/module/brick/operator.py +++ b/src/bonsai/bonsai/bim/module/brick/operator.py @@ -242,6 +242,8 @@ class SerializeBrick(bpy.types.Operator, ExportHelper): bl_label = "Serialize Brick" # Prevents crash on Blender 4.4.0. bl_description = "Save active Brick project by the provided filepath." + + filename_ext = ".ttl" filter_glob: bpy.props.StringProperty(default="*.ttl", options={"HIDDEN"}) filepath: bpy.props.StringProperty(subtype="FILE_PATH") should_save_as: bpy.props.BoolProperty(name="Should Save As", default=False, options={"HIDDEN"}) diff --git a/src/bonsai/bonsai/bim/module/clash/operator.py b/src/bonsai/bonsai/bim/module/clash/operator.py index 83fed588d2..bac9dc22c3 100644 --- a/src/bonsai/bonsai/bim/module/clash/operator.py +++ b/src/bonsai/bonsai/bim/module/clash/operator.py @@ -192,8 +192,13 @@ class ExecuteIfcClash(bpy.types.Operator, ExportHelper): bl_label = "Execute IFC Clash" bl_description = "Execute clash detection and save the information to a .bcf or .json file" filter_glob: bpy.props.StringProperty(default="*.bcf;*.json", options={"HIDDEN"}) + format: bpy.props.EnumProperty(name="Format", items=[(i, i, "") for i in ("bcf", "json")]) filepath: bpy.props.StringProperty(subtype="FILE_PATH", options={"SKIP_SAVE"}) + @property + def filename_ext(self) -> str: + return f".{self.format.lower()}" + def invoke(self, context, event): if self.filepath: return self.execute(context) diff --git a/src/bonsai/bonsai/bim/module/csv/operator.py b/src/bonsai/bonsai/bim/module/csv/operator.py index 34a296fe6f..c705ab90f2 100644 --- a/src/bonsai/bonsai/bim/module/csv/operator.py +++ b/src/bonsai/bonsai/bim/module/csv/operator.py @@ -181,6 +181,7 @@ class ExportIfcCsv(bpy.types.Operator, ExportHelper): bl_label = "Export IFC" bl_description = "Export IFC data as a spreadsheet." filename_ext = ".csv" + filter_glob: bpy.props.StringProperty(default="*.csv", options={"HIDDEN"}) filepath: bpy.props.StringProperty(subtype="FILE_PATH") @classmethod @@ -202,6 +203,8 @@ class ExportIfcCsv(bpy.types.Operator, ExportHelper): props = tool.Blender.get_csv_props() if props.format == "web": return self.execute(context) + self.filter_glob = f"*.{props.format}" + self.filename_ext = f".{props.format}" return ExportHelper.invoke(self, context, event) def execute(self, context): diff --git a/src/bonsai/bonsai/bim/module/debug/operator.py b/src/bonsai/bonsai/bim/module/debug/operator.py index 0b1c59211a..b998df97e3 100644 --- a/src/bonsai/bonsai/bim/module/debug/operator.py +++ b/src/bonsai/bonsai/bim/module/debug/operator.py @@ -528,6 +528,7 @@ class PurgeUnusedElementsByClass(bpy.types.Operator, tool.Ifc.Operator, ExportHe "ALT+CLICK to provide a path where to save the IFC file with the removed elements (note changes will be applied to the current IFC too)" ) bl_options = {"REGISTER", "UNDO"} + filename_ext = ".ifc" filepath: bpy.props.StringProperty(subtype="FILE_PATH", options={"SKIP_SAVE"}) filter_glob: bpy.props.StringProperty(default="*.ifc", options={"HIDDEN"}) diff --git a/src/bonsai/bonsai/bim/module/fm/operator.py b/src/bonsai/bonsai/bim/module/fm/operator.py index fac40439c2..919fd76821 100644 --- a/src/bonsai/bonsai/bim/module/fm/operator.py +++ b/src/bonsai/bonsai/bim/module/fm/operator.py @@ -31,9 +31,19 @@ class ExecuteIfcFM(bpy.types.Operator, ExportHelper): bl_idname = "bim.execute_ifcfm" bl_label = "Execute IfcFM" bl_description = "Export IfcFM data as a spreadsheet." - file_format: bpy.props.StringProperty() + filter_glob: bpy.props.StringProperty(default="*.csv;*.ods;*.xlsx", options={"HIDDEN"}) + @property + def filename_ext(self) -> str: + props = bpy.context.scene.BIMFMProperties + return f".{props.format}" + + def draw(self, context): + layout = self.layout + props = context.scene.BIMFMProperties + layout.prop(props, "format") + @classmethod def poll(cls, context): props = context.scene.BIMFMProperties @@ -42,11 +52,6 @@ class ExecuteIfcFM(bpy.types.Operator, ExportHelper): return False return True - def invoke(self, context, event): - props = context.scene.BIMFMProperties - self.filepath = bpy.path.ensure_ext(bpy.data.filepath, f".{props.format}") - return ExportHelper.invoke(self, context, event) - def execute(self, context): props = context.scene.BIMFMProperties ifc_file = tool.Ifc.get() @@ -105,6 +110,16 @@ class ExecuteIfcFMFederate(bpy.types.Operator, ExportHelper): bl_description = "Merge added IfcFM spreadsheets." filter_glob: bpy.props.StringProperty(default="*.ods;*.xlsx", options={"HIDDEN"}) + @property + def filename_ext(self) -> str: + props = bpy.context.scene.BIMFMProperties + return f".{props.format}" + + def draw(self, context): + layout = self.layout + props = context.scene.BIMFMProperties + layout.prop(props, "format") + @classmethod def poll(cls, context): props = context.scene.BIMFMProperties @@ -113,11 +128,6 @@ class ExecuteIfcFMFederate(bpy.types.Operator, ExportHelper): return False return True - def invoke(self, context, event): - props = context.scene.BIMFMProperties - self.filepath = bpy.path.ensure_ext(bpy.data.filepath, f".{props.format}") - return ExportHelper.invoke(self, context, event) - def execute(self, context): props = context.scene.BIMFMProperties parser = ifcfm.Parser(preset=props.engine) diff --git a/src/bonsai/bonsai/bim/module/light/operator.py b/src/bonsai/bonsai/bim/module/light/operator.py index 7ad7a5da55..0c7e632bf3 100644 --- a/src/bonsai/bonsai/bim/module/light/operator.py +++ b/src/bonsai/bonsai/bim/module/light/operator.py @@ -638,6 +638,7 @@ class RADIANCE_OT_export_material_mappings(bpy.types.Operator, ExportHelper): bl_description = "Export material mappings to a JSON file" filename_ext = ".json" + filter_glob: bpy.props.StringProperty(default="*.json", options={"HIDDEN"}) def execute(self, context): props = context.scene.radiance_exporter_properties