The MergeProject recipe now accepts a file object, not always a filepath

This commit is contained in:
Dion Moult
2024-06-29 17:01:58 +10:00
parent c7232a780a
commit 43bc979114
@@ -24,7 +24,7 @@ from logging import Logger
class Patcher: class Patcher:
def __init__(self, src: str, file: ifcopenshell.file, logger: Logger, filepath: str): def __init__(self, src: str, file: ifcopenshell.file, logger: Logger, filepath: Union[str, ifcopenshell.file]):
"""Merge two IFC models into one """Merge two IFC models into one
Note that other than combining the two IfcProject elements into one, no Note that other than combining the two IfcProject elements into one, no
@@ -37,7 +37,6 @@ class Patcher:
:param filepath: The filepath of the second IFC model to merge into the :param filepath: The filepath of the second IFC model to merge into the
first. The first model is already specified as the input to first. The first model is already specified as the input to
IfcPatch. IfcPatch.
:type filepath: str
Example: Example:
@@ -51,8 +50,11 @@ class Patcher:
self.filepath = filepath self.filepath = filepath
def patch(self): def patch(self):
source = ifcopenshell.open(self.filepath) if isinstance(self.filepath, ifcopenshell.file):
# make sure models units will match source = self.filepath
else:
source = ifcopenshell.open(self.filepath)
if (main_unit := self.get_unit_name(self.file)) != self.get_unit_name(source): if (main_unit := self.get_unit_name(self.file)) != self.get_unit_name(source):
source = ifcopenshell.util.unit.convert_file_length_units(source, main_unit) source = ifcopenshell.util.unit.convert_file_length_units(source, main_unit)