diff --git a/src/ifcopenshell-python/ifcopenshell/file.py b/src/ifcopenshell-python/ifcopenshell/file.py index 0a6bbc8594..29c991e0e7 100644 --- a/src/ifcopenshell-python/ifcopenshell/file.py +++ b/src/ifcopenshell-python/ifcopenshell/file.py @@ -32,6 +32,21 @@ from .entity_instance import entity_instance if TYPE_CHECKING: import ifcopenshell.util.schema +HEADER_FIELDS = { + "file_description": [ + "description", + "implementation_level" + ], + "file_name": [ + "name", + "time_stamp", + "author", + "organization", + "preprocessor_version", + "originating_system", + "authorization" + ] +} class Transaction: def __init__(self, ifc_file): @@ -616,6 +631,11 @@ class file: def __iter__(self) -> Generator[ifcopenshell.entity_instance, None, None]: return iter(self[id] for id in self.wrapped_data.entity_names()) + def assign_header_from(self, other): + for k, vs in HEADER_FIELDS.items(): + for v in vs: + setattr(getattr(self.header, k), v, getattr(getattr(other.header, k), v)) + def write(self, path: "os.PathLike | str", format: Optional[str] = None, zipped: bool = False) -> None: """Write ifc model to file. diff --git a/src/ifcopenshell-python/test/test_file.py b/src/ifcopenshell-python/test/test_file.py index 60b9688f86..31c77cd6e6 100644 --- a/src/ifcopenshell-python/test/test_file.py +++ b/src/ifcopenshell-python/test/test_file.py @@ -279,3 +279,10 @@ class TestFile(test.bootstrap.IFC4): element = self.file.createIfcWall() g = ifcopenshell.file.from_string(self.file.wrapped_data.to_string()) assert g.by_id(1).is_a("IfcWall") + + def test_assigning_header(self): + f = ifcopenshell.file(schema="IFC4") + f.header.file_name.name = "test" + g = ifcopenshell.file(schema="IFC4") + g.assign_header_from(f) + assert g.header.file_name.name == "test"