mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 03:21:00 +00:00
export_cost_schedules - fix confusing filename
Mentioned in #6545 Override filename to be always empty, so user won't have an expectation that csvs will be saved as a single file (currently they're always saved to a directory).
This commit is contained in:
@@ -24,6 +24,7 @@ import bonsai.tool as tool
|
|||||||
from bpy_extras.io_utils import ImportHelper, ExportHelper
|
from bpy_extras.io_utils import ImportHelper, ExportHelper
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
import bonsai.core.cost as core
|
import bonsai.core.cost as core
|
||||||
|
from pathlib import Path
|
||||||
from typing import get_args, TYPE_CHECKING, Literal
|
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_idname = "bim.export_cost_schedules"
|
||||||
bl_label = "Export Cost Schedule"
|
bl_label = "Export Cost Schedule"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
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()
|
cost_schedule: bpy.props.IntProperty()
|
||||||
format: bpy.props.EnumProperty(name="Format", items=(("CSV", "CSV", ""), ("XLSX", "XLSX", ""), ("ODS", "ODS", "")))
|
format: bpy.props.EnumProperty(name="Format", items=(("CSV", "CSV", ""), ("XLSX", "XLSX", ""), ("ODS", "ODS", "")))
|
||||||
directory: bpy.props.StringProperty(subtype="FILE_PATH")
|
directory: bpy.props.StringProperty(subtype="FILE_PATH")
|
||||||
@@ -697,7 +699,15 @@ class ExportCostSchedules(bpy.types.Operator, ExportHelper):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
cost_schedule: int
|
||||||
format: Literal["CSV", "XLSX", "ODS"]
|
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
|
@property
|
||||||
def filename_ext(self) -> str:
|
def filename_ext(self) -> str:
|
||||||
@@ -706,15 +716,12 @@ class ExportCostSchedules(bpy.types.Operator, ExportHelper):
|
|||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
cost_schedule = tool.Ifc.get().by_id(self.cost_schedule) if self.cost_schedule else None
|
cost_schedule = tool.Ifc.get().by_id(self.cost_schedule) if self.cost_schedule else None
|
||||||
r = core.export_cost_schedules(
|
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):
|
if isinstance(r, str):
|
||||||
self.report({"ERROR"}, r)
|
self.report({"ERROR"}, r)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
def invoke(self, context, event):
|
|
||||||
return ExportHelper.invoke(self, context, event)
|
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
self.layout.label(text="Choose a format")
|
self.layout.label(text="Choose a format")
|
||||||
self.layout.prop(self, "format")
|
self.layout.prop(self, "format")
|
||||||
|
|||||||
@@ -338,12 +338,12 @@ def calculate_cost_item_resource_value(ifc: tool.Ifc, cost_item: ifcopenshell.en
|
|||||||
|
|
||||||
def export_cost_schedules(
|
def export_cost_schedules(
|
||||||
cost: tool.Cost,
|
cost: tool.Cost,
|
||||||
filepath: str,
|
dirpath: str,
|
||||||
format: Literal["CSV", "ODS", "XLSX"],
|
format: Literal["CSV", "ODS", "XLSX"],
|
||||||
cost_schedule: Union[ifcopenshell.entity_instance, None] = None,
|
cost_schedule: Union[ifcopenshell.entity_instance, None] = None,
|
||||||
) -> Union[str, None]:
|
) -> Union[str, None]:
|
||||||
cost.play_sound()
|
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(
|
def clear_cost_item_assignments(
|
||||||
|
|||||||
@@ -651,7 +651,7 @@ class Cost(bonsai.core.tool.Cost):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def export_cost_schedules(
|
def export_cost_schedules(
|
||||||
cls,
|
cls,
|
||||||
filepath: str,
|
dirpath: str,
|
||||||
format: Literal["CSV", "ODS", "XLSX"],
|
format: Literal["CSV", "ODS", "XLSX"],
|
||||||
cost_schedule: Optional[ifcopenshell.entity_instance] = None,
|
cost_schedule: Optional[ifcopenshell.entity_instance] = None,
|
||||||
) -> Union[str, None]:
|
) -> Union[str, None]:
|
||||||
@@ -659,8 +659,8 @@ class Cost(bonsai.core.tool.Cost):
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if filepath:
|
if dirpath:
|
||||||
path = filepath
|
path = dirpath
|
||||||
else:
|
else:
|
||||||
path = tool.Blender.get_data_dir_path(Path("build") / "cost_schedules").__str__()
|
path = tool.Blender.get_data_dir_path(Path("build") / "cost_schedules").__str__()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user