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): 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
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"} return {"FINISHED"}
def invoke(self, context, event): 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): 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): def clear_cost_item_assignments(ifc, cost, cost_item, related_object_type):
+16 -3
View File
@@ -499,11 +499,14 @@ class Cost(blenderbim.core.tool.Cost):
@classmethod @classmethod
def export_cost_schedules(cls, format=None, cost_schedule=None): 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": if format == "CSV":
from ifc5d.ifc5Dspreadsheet import Ifc5DCsvWriter 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 = Ifc5DCsvWriter(file=tool.Ifc.get(), output=path, cost_schedule=cost_schedule)
writer.write() writer.write()
elif format == "ODS": 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 = Ifc5DXlsxWriter(file=tool.Ifc.get(), output=path, cost_schedule=cost_schedule )
writer.write() 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 @classmethod
def get_units(cls): def get_units(cls):
+19 -13
View File
@@ -30,10 +30,10 @@ import ifcopenshell.util.date
class IfcDataGetter: class IfcDataGetter:
@staticmethod @staticmethod
def get_schedules(file): def get_schedules(file, filter_by_schedule=None):
if not file: return [
return None schedule for schedule in file.by_type("IfcCostSchedule") if not filter_by_schedule or schedule == filter_by_schedule
return file.by_type("IfcCostSchedule") ]
@staticmethod @staticmethod
def canonicalise_time(time): def canonicalise_time(time):
@@ -221,10 +221,6 @@ class Ifc5Dwriter:
self.used_names = [] self.used_names = []
for i in range(26): for i in range(26):
self.column_indexes.append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i % 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: for cost_schedule in self.cost_schedules:
sheet_id = cost_schedule.id() sheet_id = cost_schedule.id()
self.sheet_data[sheet_id] = {} self.sheet_data[sheet_id] = {}
@@ -269,7 +265,7 @@ class Ifc5Dwriter:
return "{}{}".format(self.column_indexes[attribute], self.row_count) return "{}{}".format(self.column_indexes[attribute], self.row_count)
def write(self): 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.sheet_data = {}
self.parse() self.parse()
@@ -311,10 +307,14 @@ class Ifc5DOdsWriter(Ifc5Dwriter):
ns1.addElement(Number(decimalplaces="2", minintegerdigits="1", grouping="true")) ns1.addElement(Number(decimalplaces="2", minintegerdigits="1", grouping="true"))
self.doc.styles.addElement(ns1) self.doc.styles.addElement(ns1)
file_name = ""
for cost_schedule in self.cost_schedules: 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.write_table(cost_schedule)
self.doc.save(os.path.join(self.output, file_name), True)
self.doc.save(self.output, True)
def write_table(self, cost_schedule): def write_table(self, cost_schedule):
from odf.table import Table, TableRow, TableCell from odf.table import Table, TableRow, TableCell
@@ -408,8 +408,14 @@ class Ifc5DXlsxWriter(Ifc5Dwriter):
import xlsxwriter import xlsxwriter
super().write() super().write()
file_name = ""
self.workbook = xlsxwriter.Workbook(self.output + ".xlsx") 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 = [] self.used_names = []
for cost_schedule in self.cost_schedules: for cost_schedule in self.cost_schedules:
self.write_table(cost_schedule) self.write_table(cost_schedule)