From 43bc9791144822cf506e8e2b7a40a8e719777e30 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 29 Jun 2024 17:01:58 +1000 Subject: [PATCH] The MergeProject recipe now accepts a file object, not always a filepath --- src/ifcpatch/ifcpatch/recipes/MergeProject.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ifcpatch/ifcpatch/recipes/MergeProject.py b/src/ifcpatch/ifcpatch/recipes/MergeProject.py index d5a5fe191c..6bbc9bc9de 100644 --- a/src/ifcpatch/ifcpatch/recipes/MergeProject.py +++ b/src/ifcpatch/ifcpatch/recipes/MergeProject.py @@ -24,7 +24,7 @@ from logging import Logger 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 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 first. The first model is already specified as the input to IfcPatch. - :type filepath: str Example: @@ -51,8 +50,11 @@ class Patcher: self.filepath = filepath def patch(self): - source = ifcopenshell.open(self.filepath) - # make sure models units will match + if isinstance(self.filepath, ifcopenshell.file): + source = self.filepath + else: + source = ifcopenshell.open(self.filepath) + 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)