mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-10-02 21:12:07 +00:00
Assigning library references now works on IFC2X3.
This commit is contained in:
@@ -12,7 +12,10 @@ class Usecase:
|
|||||||
self.settings[key] = value
|
self.settings[key] = value
|
||||||
|
|
||||||
def execute(self):
|
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:
|
if not rels:
|
||||||
return self.file.create_entity(
|
return self.file.create_entity(
|
||||||
"IfcRelAssociatesLibrary",
|
"IfcRelAssociatesLibrary",
|
||||||
@@ -32,3 +35,8 @@ class Usecase:
|
|||||||
rel.RelatedObjects = related_objects
|
rel.RelatedObjects = related_objects
|
||||||
ifcopenshell.api.run("owner.update_owner_history", self.file, element=rel)
|
ifcopenshell.api.run("owner.update_owner_history", self.file, element=rel)
|
||||||
return 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)
|
||||||
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,)
|
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,)
|
||||||
|
|||||||
Reference in New Issue
Block a user