diff --git a/src/bonsai/bonsai/bim/module/cost/operator.py b/src/bonsai/bonsai/bim/module/cost/operator.py index 9a48e7b61c..0da7123f1c 100644 --- a/src/bonsai/bonsai/bim/module/cost/operator.py +++ b/src/bonsai/bonsai/bim/module/cost/operator.py @@ -24,6 +24,7 @@ import bonsai.tool as tool from bpy_extras.io_utils import ImportHelper, ExportHelper import bonsai.tool as tool import bonsai.core.cost as core +from pathlib import Path from typing import get_args, TYPE_CHECKING, Literal @@ -687,7 +688,8 @@ class ExportCostSchedules(bpy.types.Operator, ExportHelper): bl_idname = "bim.export_cost_schedules" bl_label = "Export Cost Schedule" bl_options = {"REGISTER", "UNDO"} - bl_description = "Export a cost schedule to a CSV, XSLX OR ODS file" + bl_description = "Export current/all cost schedules as CSV, XSLX or ODS files to the provided directory." + cost_schedule: bpy.props.IntProperty() format: bpy.props.EnumProperty(name="Format", items=(("CSV", "CSV", ""), ("XLSX", "XLSX", ""), ("ODS", "ODS", ""))) directory: bpy.props.StringProperty(subtype="FILE_PATH") @@ -697,7 +699,15 @@ class ExportCostSchedules(bpy.types.Operator, ExportHelper): ) if TYPE_CHECKING: + cost_schedule: int format: Literal["CSV", "XLSX", "ODS"] + directory: str + + def check(self, context): + if self.filepath != self.directory: + self.filepath = self.directory + return True + return False @property def filename_ext(self) -> str: @@ -706,15 +716,12 @@ class ExportCostSchedules(bpy.types.Operator, ExportHelper): def execute(self, context): cost_schedule = tool.Ifc.get().by_id(self.cost_schedule) if self.cost_schedule else None r = core.export_cost_schedules( - tool.Cost, filepath=self.directory, format=self.format, cost_schedule=cost_schedule + tool.Cost, dirpath=self.directory, format=self.format, cost_schedule=cost_schedule ) if isinstance(r, str): self.report({"ERROR"}, r) return {"FINISHED"} - def invoke(self, context, event): - return ExportHelper.invoke(self, context, event) - def draw(self, context): self.layout.label(text="Choose a format") self.layout.prop(self, "format") diff --git a/src/bonsai/bonsai/core/cost.py b/src/bonsai/bonsai/core/cost.py index 33510320d3..4811738d4c 100644 --- a/src/bonsai/bonsai/core/cost.py +++ b/src/bonsai/bonsai/core/cost.py @@ -338,12 +338,12 @@ def calculate_cost_item_resource_value(ifc: tool.Ifc, cost_item: ifcopenshell.en def export_cost_schedules( cost: tool.Cost, - filepath: str, + dirpath: str, format: Literal["CSV", "ODS", "XLSX"], cost_schedule: Union[ifcopenshell.entity_instance, None] = None, ) -> Union[str, None]: cost.play_sound() - return cost.export_cost_schedules(filepath, format, cost_schedule) + return cost.export_cost_schedules(dirpath, format, cost_schedule) def clear_cost_item_assignments( diff --git a/src/bonsai/bonsai/tool/cost.py b/src/bonsai/bonsai/tool/cost.py index 64f8026533..b507ff01cb 100644 --- a/src/bonsai/bonsai/tool/cost.py +++ b/src/bonsai/bonsai/tool/cost.py @@ -651,7 +651,7 @@ class Cost(bonsai.core.tool.Cost): @classmethod def export_cost_schedules( cls, - filepath: str, + dirpath: str, format: Literal["CSV", "ODS", "XLSX"], cost_schedule: Optional[ifcopenshell.entity_instance] = None, ) -> Union[str, None]: @@ -659,8 +659,8 @@ class Cost(bonsai.core.tool.Cost): import os import sys - if filepath: - path = filepath + if dirpath: + path = dirpath else: path = tool.Blender.get_data_dir_path(Path("build") / "cost_schedules").__str__()