mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
document.assign_document - support batching #4474
This commit is contained in:
@@ -18,22 +18,25 @@
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class TestAssignDocument(test.bootstrap.IFC4):
|
||||
def test_assigning_a_document(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
reference = ifcopenshell.api.run("document.add_reference", self.file, information=None)
|
||||
ifcopenshell.api.run("document.assign_document", self.file, product=element, document=reference)
|
||||
ifcopenshell.api.run("document.assign_document", self.file, products=[element], document=reference)
|
||||
assert element.HasAssociations[0].RelatingDocument == reference
|
||||
assert ifcopenshell.util.element.get_referenced_elements(reference) == {element}
|
||||
|
||||
def test_assigning_multiple_documents(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
reference = ifcopenshell.api.run("document.add_reference", self.file, information=None)
|
||||
ifcopenshell.api.run("document.assign_document", self.file, product=element, document=reference)
|
||||
ifcopenshell.api.run("document.assign_document", self.file, product=element2, document=reference)
|
||||
ifcopenshell.api.run("document.assign_document", self.file, products=[element, element2], document=reference)
|
||||
assert len(self.file.by_type("IfcRelAssociatesDocument")) == 1
|
||||
assert element.HasAssociations[0].RelatingDocument == reference
|
||||
assert element2.HasAssociations[0].RelatingDocument == reference
|
||||
assert element.HasAssociations[0] == element.HasAssociations[0]
|
||||
assert ifcopenshell.util.element.get_referenced_elements(reference) == {element, element2}
|
||||
|
||||
|
||||
class TestAssignDocumentIFC2X3(test.bootstrap.IFC2X3, TestAssignDocument):
|
||||
pass
|
||||
|
||||
@@ -35,7 +35,7 @@ class TestRemoveReference(test.bootstrap.IFC4):
|
||||
wall = self.file.createIfcWall()
|
||||
information = ifcopenshell.api.run("document.add_information", self.file, parent=None)
|
||||
reference = ifcopenshell.api.run("document.add_reference", self.file, information=information)
|
||||
ifcopenshell.api.run("document.assign_document", self.file, product=wall, document=reference)
|
||||
ifcopenshell.api.run("document.assign_document", self.file, products=[wall], document=reference)
|
||||
assert len(self.file.by_type("IfcRelAssociatesDocument")) == 2
|
||||
ifcopenshell.api.run("document.remove_reference", self.file, reference=reference)
|
||||
assert len(self.file.by_type("IfcDocumentReference")) == 0
|
||||
|
||||
@@ -24,7 +24,7 @@ class TestUnassignDocument(test.bootstrap.IFC4):
|
||||
def test_unassigning_a_document(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
reference = ifcopenshell.api.run("document.add_reference", self.file, information=None)
|
||||
ifcopenshell.api.run("document.assign_document", self.file, product=element, document=reference)
|
||||
ifcopenshell.api.run("document.assign_document", self.file, products=[element], document=reference)
|
||||
ifcopenshell.api.run("document.unassign_document", self.file, product=element, document=reference)
|
||||
assert not element.HasAssociations
|
||||
assert not len(self.file.by_type("IfcRelAssociatesDocument"))
|
||||
@@ -33,8 +33,8 @@ class TestUnassignDocument(test.bootstrap.IFC4):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
reference = ifcopenshell.api.run("document.add_reference", self.file, information=None)
|
||||
ifcopenshell.api.run("document.assign_document", self.file, product=element, document=reference)
|
||||
ifcopenshell.api.run("document.assign_document", self.file, product=element2, document=reference)
|
||||
ifcopenshell.api.run("document.assign_document", self.file, products=[element], document=reference)
|
||||
ifcopenshell.api.run("document.assign_document", self.file, products=[element2], document=reference)
|
||||
ifcopenshell.api.run("document.unassign_document", self.file, product=element, document=reference)
|
||||
assert not element.HasAssociations
|
||||
assert element2.HasAssociations[0].RelatingDocument == reference
|
||||
|
||||
@@ -254,3 +254,10 @@ class TestTemporarySupportForDeprecatedAPIArguments(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("library.assign_reference", self.file, products=[product], reference=reference)
|
||||
ifcopenshell.api.run("library.unassign_reference", self.file, product=product, reference=reference)
|
||||
assert len(self.file.by_type("IfcRelAssociatesLibrary")) == 0
|
||||
|
||||
@deprecation_check
|
||||
def test_assigning_a_document(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
reference = ifcopenshell.api.run("document.add_reference", self.file, information=None)
|
||||
ifcopenshell.api.run("document.assign_document", self.file, product=element, document=reference)
|
||||
assert element.HasAssociations[0].RelatingDocument == reference
|
||||
|
||||
Reference in New Issue
Block a user