2021-03-05 15:37:40 +11:00
|
|
|
import ifcopenshell
|
2021-03-27 22:52:52 +11:00
|
|
|
import ifcopenshell.api
|
2021-03-05 15:37:40 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Usecase:
|
2021-03-27 19:14:32 +11:00
|
|
|
def __init__(self, file, **settings):
|
2021-03-05 15:37:40 +11:00
|
|
|
self.file = file
|
|
|
|
|
self.settings = {
|
|
|
|
|
"product": None,
|
|
|
|
|
"group": None,
|
|
|
|
|
}
|
|
|
|
|
for key, value in settings.items():
|
|
|
|
|
self.settings[key] = value
|
|
|
|
|
|
|
|
|
|
def execute(self):
|
|
|
|
|
if not self.settings["group"].IsGroupedBy:
|
|
|
|
|
return self.file.create_entity("IfcRelAssignsToGroup", **{
|
|
|
|
|
"GlobalId": ifcopenshell.guid.new(),
|
2021-03-27 22:52:52 +11:00
|
|
|
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
2021-03-05 15:37:40 +11:00
|
|
|
"RelatedObjects": [self.settings["product"]],
|
|
|
|
|
"RelatingGroup": self.settings["group"]
|
|
|
|
|
})
|
|
|
|
|
rel = self.settings["group"].IsGroupedBy[0]
|
|
|
|
|
related_objects = set(rel.RelatedObjects) or set()
|
|
|
|
|
related_objects.add(self.settings["product"])
|
|
|
|
|
rel.RelatedObjects = list(related_objects)
|
2021-03-27 22:52:52 +11:00
|
|
|
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
|