You can now add cost items into a cost schedule, and as sub items to a parent cost item. Thanks myoualid and Jesusbill!

This commit is contained in:
Dion Moult
2021-04-10 20:40:35 +10:00
parent 3102dbcd44
commit df437fd3e3
7 changed files with 199 additions and 17 deletions
@@ -0,0 +1,28 @@
import ifcopenshell.api
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"cost_schedule": None, "cost_item": None}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
cost_item = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcCostItem")
if self.settings["cost_schedule"]:
self.file.create_entity(
"IfcRelAssignsToControl",
**{
"GlobalId": ifcopenshell.guid.new(),
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
"RelatedObjects": [cost_item],
"RelatingControl": self.settings["cost_schedule"],
}
)
elif self.settings["cost_item"]:
ifcopenshell.api.run(
"nest.assign_object", self.file, object=cost_item, relating_object=self.settings["cost_item"]
)
return cost_item
@@ -4,15 +4,19 @@ import ifcopenshell.util.date
class Data:
is_loaded = False
cost_schedules = {}
cost_items = {}
@classmethod
def purge(cls):
cls.is_loaded = False
cls.cost_schedules = {}
cls.cost_items = {}
@classmethod
def load(cls, file):
cls.cost_schedules = {}
cls.cost_items = {}
for cost_schedule in file.by_type("IfcCostSchedule"):
data = cost_schedule.get_info()
del data["OwnerHistory"]
@@ -20,5 +24,21 @@ class Data:
data["SubmittedOn"] = ifcopenshell.util.date.ifc2datetime(data["SubmittedOn"])
if data["UpdateDate"]:
data["UpdateDate"] = ifcopenshell.util.date.ifc2datetime(data["UpdateDate"])
data["RelatedObjects"] = []
for rel in cost_schedule.Controls:
for related_object in rel.RelatedObjects:
if related_object.is_a("IfcCostItem"):
data["RelatedObjects"].append(related_object.id())
break # We are only allowed one summary cost item
cls.cost_schedules[cost_schedule.id()] = data
for cost_item in file.by_type("IfcCostItem"):
data = cost_item.get_info()
del data["OwnerHistory"]
del data["CostValues"]
del data["CostQuantities"]
data["RelatedObjects"] = []
for rel in cost_item.IsNestedBy:
[data["RelatedObjects"].append(o.id()) for o in rel.RelatedObjects if o.is_a("IfcCostItem")]
cls.cost_items[cost_item.id()] = data
cls.is_loaded=True
@@ -0,0 +1,53 @@
import ifcopenshell
import ifcopenshell.api
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {
"object": None,
"relating_object": None,
}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
nests = None
if self.settings["object"].Nests:
nests = self.settings["object"].Nests[0]
is_nested_by = None
for rel in self.settings["relating_object"].IsNestedBy:
if rel.is_a("IfcRelNests"):
is_nested_by = rel
break
if nests and nests == is_nested_by:
return
if nests:
related_objects = list(nests.RelatedObjects)
related_objects.remove(self.settings["object"])
if related_objects:
nests.RelatedObjects = related_objects
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": nests})
else:
self.file.remove(nests)
if is_nested_by:
related_objects = list(is_nested_by.RelatedObjects)
related_objects.append(self.settings["object"])
is_nested_by.RelatedObjects = related_objects
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": is_nested_by})
else:
is_nested_by = self.file.create_entity(
"IfcRelNests",
**{
"GlobalId": ifcopenshell.guid.new(),
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
"RelatedObjects": [self.settings["object"]],
"RelatingObject": self.settings["relating_object"],
}
)
return is_nested_by