ifcpatch MergeProjects - make logger arg optional

This commit is contained in:
Andrej730
2026-02-27 15:17:35 +05:00
parent a26dbe252a
commit 9005333f53
+12 -4
View File
@@ -16,9 +16,11 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcPatch. If not, see <http://www.gnu.org/licenses/>. # along with IfcPatch. If not, see <http://www.gnu.org/licenses/>.
from collections.abc import Sequence
from logging import Logger from logging import Logger
from typing import Union from typing import Union
import ifcpatch
import ifcopenshell import ifcopenshell
import ifcopenshell.util.element import ifcopenshell.util.element
import ifcopenshell.util.geolocation import ifcopenshell.util.geolocation
@@ -29,8 +31,13 @@ import ifcpatch
from ifcpatch.recipes.SetFalseOrigin import Patcher as SetFalseOrigin from ifcpatch.recipes.SetFalseOrigin import Patcher as SetFalseOrigin
class Patcher: class Patcher(ifcpatch.BasePatcher):
def __init__(self, file: ifcopenshell.file, logger: Logger, filepaths: list[Union[str, ifcopenshell.file]]): def __init__(
self,
file: ifcopenshell.file,
logger: Logger | None = None,
filepaths: Sequence[Union[str, ifcopenshell.file]] = (),
):
"""Merge two or more IFC models into one """Merge two or more IFC models into one
Note that other than combining the two (or more) IfcProject elements into Note that other than combining the two (or more) IfcProject elements into
@@ -51,8 +58,7 @@ class Patcher:
ifcpatch.execute({"input": "input.ifc", "file": model, "recipe": "MergeProjects", "arguments": ["/path/to/model2.ifc"]}) ifcpatch.execute({"input": "input.ifc", "file": model, "recipe": "MergeProjects", "arguments": ["/path/to/model2.ifc"]})
""" """
self.file = file super().__init__(file, logger)
self.logger = logger
self.filepaths = filepaths self.filepaths = filepaths
def patch(self): def patch(self):
@@ -62,6 +68,8 @@ class Patcher:
"replace it with a list of file/filepaths." "replace it with a list of file/filepaths."
) )
self.filepaths = [self.filepaths] self.filepaths = [self.filepaths]
if len(self.filepaths) == 0:
raise ValueError("At least one file/filepath must be provided to merge with the main model.")
for filepath in self.filepaths: for filepath in self.filepaths:
if isinstance(filepath, ifcopenshell.file): if isinstance(filepath, ifcopenshell.file):
other = filepath other = filepath