From f75045f0c518133838dd9bb912254b1bbda0155e Mon Sep 17 00:00:00 2001 From: falken10vdl <33285113+falken10vdl@users.noreply.github.com> Date: Fri, 4 Jul 2025 12:35:17 +0200 Subject: [PATCH] See #6570. Now it is possible to remove the csv cost file link. This is a followup to that issue. In this particular case, a remove csv link button is added next to the refresh csv link button. --- src/bonsai/bonsai/bim/module/cost/__init__.py | 1 + src/bonsai/bonsai/bim/module/cost/operator.py | 28 +++++++++++++++++++ src/bonsai/bonsai/bim/module/cost/ui.py | 1 + src/bonsai/bonsai/core/cost.py | 6 ++++ src/bonsai/bonsai/tool/cost.py | 1 - 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/bonsai/bonsai/bim/module/cost/__init__.py b/src/bonsai/bonsai/bim/module/cost/__init__.py index e2fa66f24a..c148faeedd 100644 --- a/src/bonsai/bonsai/bim/module/cost/__init__.py +++ b/src/bonsai/bonsai/bim/module/cost/__init__.py @@ -63,6 +63,7 @@ classes = ( operator.HighlightProductCostItem, operator.ImportCostScheduleCsv, operator.RefreshCostScheduleCsv, + operator.RemoveCostScheduleCsvLink, operator.LoadCostItemElementQuantities, operator.LoadCostItemQuantities, operator.ShowAssignedCostRate, diff --git a/src/bonsai/bonsai/bim/module/cost/operator.py b/src/bonsai/bonsai/bim/module/cost/operator.py index cfba6ade07..daa8cbb898 100644 --- a/src/bonsai/bonsai/bim/module/cost/operator.py +++ b/src/bonsai/bonsai/bim/module/cost/operator.py @@ -615,6 +615,34 @@ class RefreshCostScheduleCsv(bpy.types.Operator, tool.Ifc.Operator): return {"FINISHED"} +class RemoveCostScheduleCsvLink(bpy.types.Operator, tool.Ifc.Operator): + bl_idname = "bim.remove_cost_schedule_csv_link" + bl_label = "Remove CSV Link" + bl_description = "Remove the link to the CSV file and delete the related document reference" + bl_options = {"REGISTER", "UNDO"} + + @classmethod + def poll(cls, context): + props = tool.Cost.get_cost_props() + if not props.active_cost_schedule_id: + cls.poll_message_set("No active cost schedule") + return False + + file_path = tool.Cost.get_cost_schedule_csv_filepath(props.active_cost_schedule_id) + if not file_path: + cls.poll_message_set("No CSV file associated with this cost schedule") + return False + + return True + + def _execute(self, context): + core.remove_cost_schedule_csv_link(tool.Cost) + return {"FINISHED"} + + def invoke(self, context, event): + return context.window_manager.invoke_confirm(self, event) + + class AddCostColumn(bpy.types.Operator): bl_idname = "bim.add_cost_column" bl_label = "Add Cost Column" diff --git a/src/bonsai/bonsai/bim/module/cost/ui.py b/src/bonsai/bonsai/bim/module/cost/ui.py index bea25aef8a..b96cc6cb30 100644 --- a/src/bonsai/bonsai/bim/module/cost/ui.py +++ b/src/bonsai/bonsai/bim/module/cost/ui.py @@ -84,6 +84,7 @@ class BIM_PT_cost_schedules(Panel): if file_path: row_1.label(text=file_path) row_1.operator("bim.refresh_cost_schedule_csv", icon="FILE_REFRESH", text="") + row_1.operator("bim.remove_cost_schedule_csv_link", icon="X", text="") else: row_1.label(text="No CSV file found") row_1.operator("bim.import_cost_schedule_csv", icon="IMPORT", text="") diff --git a/src/bonsai/bonsai/core/cost.py b/src/bonsai/bonsai/core/cost.py index bbb9747380..d640ba8083 100644 --- a/src/bonsai/bonsai/core/cost.py +++ b/src/bonsai/bonsai/core/cost.py @@ -361,6 +361,12 @@ def refresh_cost_schedule_csv(cost: type[tool.Cost]) -> Optional[str]: cost.load_cost_schedule_tree() +def remove_cost_schedule_csv_link(cost: type[tool.Cost]) -> None: + cost_schedule = cost.get_active_cost_schedule() + if cost_schedule: + cost.remove_csv_filepath(cost_schedule) + + def add_cost_column(cost: type[tool.Cost], name: str) -> None: cost.add_cost_column(name) diff --git a/src/bonsai/bonsai/tool/cost.py b/src/bonsai/bonsai/tool/cost.py index 7708b72146..411b0459a2 100644 --- a/src/bonsai/bonsai/tool/cost.py +++ b/src/bonsai/bonsai/tool/cost.py @@ -697,7 +697,6 @@ class Cost(bonsai.core.tool.Cost): def refresh_cost_schedule_csv(cls): """Refresh cost schedule from CSV file stored in document references.""" from ifc5d.csv2ifc import Csv2Ifc - import os props = cls.get_cost_props() cost_schedule_id = props.active_cost_schedule_id