Exporting cost schedules opens the folder directory

This commit is contained in:
Sigma Dimensions
2023-05-31 16:21:19 +01:00
parent aa63055a46
commit 9a02fc02db
4 changed files with 41 additions and 19 deletions
@@ -634,7 +634,9 @@ class ExportCostSchedules(bpy.types.Operator):
def execute(self, context):
cost_schedule = tool.Ifc.get().by_id(self.cost_schedule) if self.cost_schedule else None
core.export_cost_schedules(tool.Cost, format=self.format, cost_schedule=cost_schedule)
r = core.export_cost_schedules(tool.Cost, format=self.format, cost_schedule=cost_schedule)
if isinstance(r, str):
self.report({"ERROR"}, r)
return {"FINISHED"}
def invoke(self, context, event):
+2 -1
View File
@@ -237,7 +237,8 @@ def calculate_cost_item_resource_value(ifc, cost_item):
def export_cost_schedules(cost, format, cost_schedule=None):
cost.export_cost_schedules(format, cost_schedule)
cost.play_sound()
return cost.export_cost_schedules(format, cost_schedule)
def clear_cost_item_assignments(ifc, cost, cost_item, related_object_type):
+17 -4
View File
@@ -499,11 +499,14 @@ class Cost(blenderbim.core.tool.Cost):
@classmethod
def export_cost_schedules(cls, format=None, cost_schedule=None):
path = os.path.join(bpy.context.scene.BIMProperties.data_dir, "build", "cost_schedules")
import subprocess
import os
import sys
path = os.path.join(bpy.context.scene.BIMProperties.data_dir, "cost_schedules")
if not os.path.exists(path):
os.makedirs(path)
if format == "CSV":
from ifc5d.ifc5Dspreadsheet import Ifc5DCsvWriter
if not os.path.exists(path):
os.makedirs(path)
writer = Ifc5DCsvWriter(file=tool.Ifc.get(), output=path, cost_schedule=cost_schedule)
writer.write()
elif format == "ODS":
@@ -516,6 +519,16 @@ class Cost(blenderbim.core.tool.Cost):
writer = Ifc5DXlsxWriter(file=tool.Ifc.get(), output=path, cost_schedule=cost_schedule )
writer.write()
try:
if path:
if sys.platform == "win32":
os.startfile(path)
elif sys.platform == "darwin":
subprocess.call(["open", path])
elif sys.platform == "linux":
subprocess.call(["xdg-open", path])
except:
return 'Could not open file location'
@classmethod
def get_units(cls):
@@ -659,4 +672,4 @@ class Cost(blenderbim.core.tool.Cost):
@classmethod
def has_schedules(cls):
return bool(tool.Ifc.get().by_type("IfcCostSchedule"))
return bool(tool.Ifc.get().by_type("IfcCostSchedule"))
+19 -13
View File
@@ -30,10 +30,10 @@ import ifcopenshell.util.date
class IfcDataGetter:
@staticmethod
def get_schedules(file):
if not file:
return None
return file.by_type("IfcCostSchedule")
def get_schedules(file, filter_by_schedule=None):
return [
schedule for schedule in file.by_type("IfcCostSchedule") if not filter_by_schedule or schedule == filter_by_schedule
]
@staticmethod
def canonicalise_time(time):
@@ -221,10 +221,6 @@ class Ifc5Dwriter:
self.used_names = []
for i in range(26):
self.column_indexes.append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i % 26])
if self.cost_schedule:
for cost_schedule in self.cost_schedules:
if cost_schedule.id() != self.cost_schedule.id():
self.cost_schedules.remove(cost_schedule)
for cost_schedule in self.cost_schedules:
sheet_id = cost_schedule.id()
self.sheet_data[sheet_id] = {}
@@ -269,7 +265,7 @@ class Ifc5Dwriter:
return "{}{}".format(self.column_indexes[attribute], self.row_count)
def write(self):
self.cost_schedules = IfcDataGetter.get_schedules(self.file)
self.cost_schedules = IfcDataGetter.get_schedules(self.file, self.cost_schedule)
self.sheet_data = {}
self.parse()
@@ -311,10 +307,14 @@ class Ifc5DOdsWriter(Ifc5Dwriter):
ns1.addElement(Number(decimalplaces="2", minintegerdigits="1", grouping="true"))
self.doc.styles.addElement(ns1)
file_name = ""
for cost_schedule in self.cost_schedules:
if file_name:
file_name += "_" + cost_schedule.Name or ""
else:
file_name += cost_schedule.Name or ""
self.write_table(cost_schedule)
self.doc.save(self.output, True)
self.doc.save(os.path.join(self.output, file_name), True)
def write_table(self, cost_schedule):
from odf.table import Table, TableRow, TableCell
@@ -408,8 +408,14 @@ class Ifc5DXlsxWriter(Ifc5Dwriter):
import xlsxwriter
super().write()
self.workbook = xlsxwriter.Workbook(self.output + ".xlsx")
file_name = ""
for cost_schedule in self.cost_schedules:
if file_name:
file_name += "_" + cost_schedule.Name or ""
else:
file_name += cost_schedule.Name or ""
self.file_path = os.path.join(self.output, "{}.xlsx".format(file_name))
self.workbook = xlsxwriter.Workbook(self.file_path)
self.used_names = []
for cost_schedule in self.cost_schedules:
self.write_table(cost_schedule)