ifcopenshell.file.assign_header_from() to copy header

This commit is contained in:
Thomas Krijnen
2024-09-03 18:49:05 +02:00
parent bea837299e
commit eb7411b310
2 changed files with 27 additions and 0 deletions
@@ -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.
@@ -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"