mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 14:02:27 +00:00
ifcopenshell.file.assign_header_from() to copy header
This commit is contained in:
@@ -32,6 +32,21 @@ from .entity_instance import entity_instance
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import ifcopenshell.util.schema
|
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:
|
class Transaction:
|
||||||
def __init__(self, ifc_file):
|
def __init__(self, ifc_file):
|
||||||
@@ -616,6 +631,11 @@ class file:
|
|||||||
def __iter__(self) -> Generator[ifcopenshell.entity_instance, None, None]:
|
def __iter__(self) -> Generator[ifcopenshell.entity_instance, None, None]:
|
||||||
return iter(self[id] for id in self.wrapped_data.entity_names())
|
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:
|
def write(self, path: "os.PathLike | str", format: Optional[str] = None, zipped: bool = False) -> None:
|
||||||
"""Write ifc model to file.
|
"""Write ifc model to file.
|
||||||
|
|
||||||
|
|||||||
@@ -279,3 +279,10 @@ class TestFile(test.bootstrap.IFC4):
|
|||||||
element = self.file.createIfcWall()
|
element = self.file.createIfcWall()
|
||||||
g = ifcopenshell.file.from_string(self.file.wrapped_data.to_string())
|
g = ifcopenshell.file.from_string(self.file.wrapped_data.to_string())
|
||||||
assert g.by_id(1).is_a("IfcWall")
|
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user