mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
You can now add IFC subdocuments or supersede documents
This commit is contained in:
@@ -29,12 +29,12 @@ class Usecase:
|
||||
def execute(self):
|
||||
id_attribute = "DocumentId" if self.file.schema == "IFC2X3" else "Identification"
|
||||
information = self.file.create_entity(
|
||||
"IfcDocumentInformation", **{id_attribute: ifcopenshell.guid.new(), "Name": "Unnamed"}
|
||||
"IfcDocumentInformation", **{id_attribute: "X", "Name": "Unnamed"}
|
||||
)
|
||||
parent = self.settings["parent"]
|
||||
if not parent and self.file.by_type("IfcProject"):
|
||||
parent = self.file.by_type("IfcProject")[0]
|
||||
if parent.is_a("IfcProject") or prarent.is_a("IfcContext"):
|
||||
if parent.is_a("IfcProject") or parent.is_a("IfcContext"):
|
||||
self.file.create_entity(
|
||||
"IfcRelAssociatesDocument",
|
||||
GlobalId=ifcopenshell.guid.new(),
|
||||
@@ -42,4 +42,16 @@ class Usecase:
|
||||
RelatingDocument=information,
|
||||
RelatedObjects=[parent],
|
||||
)
|
||||
elif parent.is_a("IfcDocumentInformation"):
|
||||
if parent.IsPointer:
|
||||
rel = parent.IsPointer[0]
|
||||
documents = set(rel.RelatedDocuments)
|
||||
documents.add(information)
|
||||
rel.RelatedDocuments = list(documents)
|
||||
else:
|
||||
self.file.create_entity(
|
||||
"IfcDocumentInformationRelationship",
|
||||
RelatingDocument=parent,
|
||||
RelatedDocuments=[information]
|
||||
)
|
||||
return information
|
||||
|
||||
@@ -22,7 +22,7 @@ import ifcopenshell.api
|
||||
|
||||
class TestAddInformation(test.bootstrap.IFC4):
|
||||
def test_adding_information(self):
|
||||
self.file.createIfcProject()
|
||||
project = self.file.createIfcProject()
|
||||
element = ifcopenshell.api.run("document.add_information", self.file, parent=None)
|
||||
assert element.is_a("IfcDocumentInformation")
|
||||
assert len(self.file.by_type("IfcDocumentInformation")) == 1
|
||||
@@ -33,3 +33,15 @@ class TestAddInformation(test.bootstrap.IFC4):
|
||||
rel = element.DocumentInfoForObjects[0]
|
||||
assert rel.is_a("IfcRelAssociatesDocument")
|
||||
assert rel.RelatedObjects[0] == project
|
||||
|
||||
def test_adding_a_subdocument(self):
|
||||
project = self.file.createIfcProject()
|
||||
parent = ifcopenshell.api.run("document.add_information", self.file, parent=None)
|
||||
element = ifcopenshell.api.run("document.add_information", self.file, parent=parent)
|
||||
assert element.is_a("IfcDocumentInformation")
|
||||
assert len(self.file.by_type("IfcDocumentInformation")) == 2
|
||||
assert element.IsPointedTo[0].RelatingDocument == parent
|
||||
assert parent.IsPointer[0].RelatedDocuments[0] == element
|
||||
element2 = ifcopenshell.api.run("document.add_information", self.file, parent=parent)
|
||||
assert element in parent.IsPointer[0].RelatedDocuments
|
||||
assert element2 in parent.IsPointer[0].RelatedDocuments
|
||||
|
||||
Reference in New Issue
Block a user