From a62b177b194735b6232fa56de53cf9cbd4f84448 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 3 Feb 2026 19:20:01 +0500 Subject: [PATCH] Bonsai - fix error drag'n'dropping ifc files in Blender 4.5.6 Example error: ``` Error: Couldn't find IFC file: 'L:/OD_Cool_Car_Guys.ifc'. Traceback (most recent call last): File "\Blender Foundation\Blender\4.5\extensions\.local\lib\python3.11\site-packages\bonsai\bim\module\project\operator.py", line 2759, in invoke return bpy.ops.bim.load_project(filepath=(filepath / clean_up_path(self.files[0].name)).as_posix()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "\blender-4.5.6-lts.a78963ed6435\4.5\scripts\modules\bpy\ops.py", line 109, in __call__ ret = _op_call(self.idname_py(), kw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: Error: Couldn't find IFC file: 'L:/OD_Cool_Car_Guys.ifc'. ``` --- src/bonsai/bonsai/bim/module/project/operator.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/project/operator.py b/src/bonsai/bonsai/bim/module/project/operator.py index 8fad709de3..b6f63f13ca 100644 --- a/src/bonsai/bonsai/bim/module/project/operator.py +++ b/src/bonsai/bonsai/bim/module/project/operator.py @@ -2735,17 +2735,27 @@ class IFCFileHandlerOperator(bpy.types.Operator): # Keeping code in .invoke() as we'll probably add some # popup windows later. + def clean_up_path(path: str) -> str: + # In Blender 4.5.6 there was a bug producing unncesseary double slash prefix + # breaking the paths. Issue is not present in 5.0+ and presumably will be solved in 4.5.7 too. + # https://projects.blender.org/blender/blender/issues/153822 + if bpy.app.version == (4, 5, 6): + blender_prefix = "//" + if path.startswith(blender_prefix): + return path.removeprefix(blender_prefix) + return path + # `files` contain only .ifc files. filepath = Path(self.directory) # If user is just drag'n'dropping a single file -> load it as a new project, # if they're holding ALT -> link the file/files to the current project. if event.alt: # Passing self.files directly results in TypeError. - serialized_files = [{"name": f.name} for f in self.files] + serialized_files = [{"name": clean_up_path(f.name)} for f in self.files] return bpy.ops.bim.link_ifc(directory=self.directory, files=serialized_files) else: if len(self.files) == 1: - return bpy.ops.bim.load_project(filepath=(filepath / self.files[0].name).as_posix()) + return bpy.ops.bim.load_project(filepath=(filepath / clean_up_path(self.files[0].name)).as_posix()) else: self.report( {"INFO"},