Files
IfcOpenShell/src/ifcopenshell-python/ifcopenshell/api/pset/add_qto.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
1.2 KiB
Python
Raw Normal View History

2021-01-13 21:26:10 +11:00
import ifcopenshell
import ifcopenshell.api
2021-01-13 21:26:10 +11:00
class Usecase:
def __init__(self, file, **settings):
2021-01-13 21:26:10 +11:00
self.file = file
self.settings = {"product": None, "name": None}
2021-01-13 21:26:10 +11:00
for key, value in settings.items():
self.settings[key] = value
def execute(self):
if self.settings["product"].is_a("IfcObject"):
for rel in self.settings["product"].IsDefinedBy or []:
if (
rel.is_a("IfcRelDefinesByProperties")
and rel.RelatingPropertyDefinition.Name == self.settings["name"]
):
return rel.RelatingPropertyDefinition
2021-01-13 21:26:10 +11:00
qto = self.file.create_entity(
"IfcElementQuantity", **{"GlobalId": ifcopenshell.guid.new(), "Name": self.settings["name"]}
2021-01-13 21:26:10 +11:00
)
self.file.create_entity(
"IfcRelDefinesByProperties",
**{
"GlobalId": ifcopenshell.guid.new(),
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
2021-01-13 21:26:10 +11:00
"RelatedObjects": [self.settings["product"]],
"RelatingPropertyDefinition": qto,
}
)
return qto