From 18ad025c5dde0d064545a36f2d5d22d0bd79e208 Mon Sep 17 00:00:00 2001 From: Nelson Henrique <67214937+nelsonhp3@users.noreply.github.com> Date: Thu, 8 Jun 2023 00:15:27 +0000 Subject: [PATCH] implements fileselect to export_cost_schedules --- src/blenderbim/blenderbim/bim/module/cost/operator.py | 6 ++++-- src/blenderbim/blenderbim/core/cost.py | 4 ++-- src/blenderbim/blenderbim/core/tool.py | 2 +- src/blenderbim/blenderbim/tool/cost.py | 8 ++++++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/cost/operator.py b/src/blenderbim/blenderbim/bim/module/cost/operator.py index 50b42bd672..320e3840f7 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/operator.py +++ b/src/blenderbim/blenderbim/bim/module/cost/operator.py @@ -631,17 +631,19 @@ class ExportCostSchedules(bpy.types.Operator): bl_description = "Export a cost schedule to a CSV, XSLX OR ODS file" cost_schedule: bpy.props.IntProperty() format: bpy.props.EnumProperty("Format", items=(("CSV", "CSV", ""), ("XLSX", "XLSX", ""), ("ODS", "ODS", ""))) + filepath: bpy.props.StringProperty(subtype="FILE_PATH") 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, format=self.format, cost_schedule=cost_schedule) + r = core.export_cost_schedules(tool.Cost, filepath=self.filepath, format=self.format, cost_schedule=cost_schedule) if isinstance(r, str): self.report({"ERROR"}, r) return {"FINISHED"} def invoke(self, context, event): wm = context.window_manager - return wm.invoke_props_dialog(self) + wm.fileselect_add(self) + return {"RUNNING_MODAL"} def draw(self, context): self.layout.label(text="Choose a format") diff --git a/src/blenderbim/blenderbim/core/cost.py b/src/blenderbim/blenderbim/core/cost.py index 6d1d2e9cd6..4cc4db3d5b 100644 --- a/src/blenderbim/blenderbim/core/cost.py +++ b/src/blenderbim/blenderbim/core/cost.py @@ -236,9 +236,9 @@ def calculate_cost_item_resource_value(ifc, cost_item): ifc.run("cost.calculate_cost_item_resource_value", cost_item=cost_item) -def export_cost_schedules(cost, format, cost_schedule=None): +def export_cost_schedules(cost, filepath, format, cost_schedule=None): cost.play_sound() - return cost.export_cost_schedules(format, cost_schedule) + return cost.export_cost_schedules(filepath, format, cost_schedule) def clear_cost_item_assignments(ifc, cost, cost_item, related_object_type): diff --git a/src/blenderbim/blenderbim/core/tool.py b/src/blenderbim/blenderbim/core/tool.py index a2c4d4c704..cfe42c95e4 100644 --- a/src/blenderbim/blenderbim/core/tool.py +++ b/src/blenderbim/blenderbim/core/tool.py @@ -165,7 +165,7 @@ class Cost: def expand_cost_item_rate(cls, cost_item): pass def expand_cost_item(cls, cost_item): pass def expand_cost_items(cls): pass - def export_cost_schedules(cls, format, cost_schedule): pass + def export_cost_schedules(cls, filepath, format, cost_schedule): pass def format_unit(cls, unit): pass def get_active_cost_item(cls): pass def get_active_cost_schedule(cls): pass diff --git a/src/blenderbim/blenderbim/tool/cost.py b/src/blenderbim/blenderbim/tool/cost.py index 328d41575f..f007e6ff01 100644 --- a/src/blenderbim/blenderbim/tool/cost.py +++ b/src/blenderbim/blenderbim/tool/cost.py @@ -505,11 +505,15 @@ class Cost(blenderbim.core.tool.Cost): props.is_cost_update_enabled = True @classmethod - def export_cost_schedules(cls, format=None, cost_schedule=None): + def export_cost_schedules(cls, filepath, format=None, cost_schedule=None): import subprocess import os import sys - path = os.path.join(bpy.context.scene.BIMProperties.data_dir, "cost_schedules") + if filepath: + path=filepath + else: + path = os.path.join(bpy.context.scene.BIMProperties.data_dir, "build", "cost_schedules") + if not os.path.exists(path): os.makedirs(path) if format == "CSV":