Assigning library references now works on IFC2X3.

This commit is contained in:
Dion Moult
2021-11-29 20:16:25 +11:00
parent c0f547c6e4
commit d638405ff8
2 changed files with 29 additions and 1 deletions
@@ -12,7 +12,10 @@ class Usecase:
self.settings[key] = value
def execute(self):
rels = self.settings["reference"].LibraryRefForObjects
if self.file.schema == "IFC2X3":
rels = self.get_ifc2x3_rels()
else:
rels = self.settings["reference"].LibraryRefForObjects
if not rels:
return self.file.create_entity(
"IfcRelAssociatesLibrary",
@@ -32,3 +35,8 @@ class Usecase:
rel.RelatedObjects = related_objects
ifcopenshell.api.run("owner.update_owner_history", self.file, element=rel)
return rel
def get_ifc2x3_rels(self):
return [
r for r in self.file.by_type("IfcRelAssociatesLibrary") if r.RelatingLibrary == self.settings["reference"]
]
@@ -18,3 +18,23 @@ class TestAssignReference(test.bootstrap.IFC4):
ifcopenshell.api.run("library.assign_reference", self.file, product=product, reference=reference)
ifcopenshell.api.run("library.assign_reference", self.file, product=product, reference=reference)
assert reference.LibraryRefForObjects[0].RelatedObjects == (product,)
class TestAssignReference(test.bootstrap.IFC2X3):
def test_assigning_a_reference(self):
reference = self.file.createIfcLibraryReference()
product = self.file.createIfcWall()
product2 = self.file.createIfcWall()
ifcopenshell.api.run("library.assign_reference", self.file, product=product, reference=reference)
rel = self.file.by_type("IfcRelAssociatesLibrary")[0]
assert rel.RelatedObjects == (product,)
ifcopenshell.api.run("library.assign_reference", self.file, product=product2, reference=reference)
assert rel.RelatedObjects == (product, product2)
def test_not_assigning_twice(self):
reference = self.file.createIfcLibraryReference()
product = self.file.createIfcWall()
ifcopenshell.api.run("library.assign_reference", self.file, product=product, reference=reference)
ifcopenshell.api.run("library.assign_reference", self.file, product=product, reference=reference)
rel = self.file.by_type("IfcRelAssociatesLibrary")[0]
assert rel.RelatedObjects == (product,)