You can now add / remove cost schedules

This commit is contained in:
Dion Moult
2021-04-03 19:46:39 +11:00
parent 89557460c8
commit 966af5a757
7 changed files with 131 additions and 0 deletions
@@ -0,0 +1,22 @@
import ifcopenshell.api
import ifcopenshell.util.date
from datetime import datetime
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"name": None, "predefined_type": "NOTDEFINED", "start_time": datetime.now()}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
cost_schedule = ifcopenshell.api.run(
"root.create_entity",
self.file,
ifc_class="IfcCostSchedule",
predefined_type=self.settings["predefined_type"],
name=self.settings["name"],
)
cost_schedule.UpdateDate = ifcopenshell.util.date.datetime2ifc(datetime.now(), "IfcDateTime")
return cost_schedule
@@ -0,0 +1,24 @@
import ifcopenshell.util.date
class Data:
is_loaded = False
cost_schedules = {}
@classmethod
def purge(cls):
cls.is_loaded = False
cls.cost_schedules = {}
@classmethod
def load(cls, file):
cls.cost_schedules = {}
for cost_schedule in file.by_type("IfcCostSchedule"):
data = cost_schedule.get_info()
del data["OwnerHistory"]
if data["SubmittedOn"]:
data["SubmittedOn"] = ifcopenshell.util.date.ifc2datetime(data["SubmittedOn"])
if data["UpdateDate"]:
data["UpdateDate"] = ifcopenshell.util.date.ifc2datetime(data["UpdateDate"])
cls.cost_schedules[cost_schedule.id()] = data
cls.is_loaded=True
@@ -0,0 +1,10 @@
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"cost_schedule": None}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
# TODO: do a deep purge
self.file.remove(self.settings["cost_schedule"])