mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 02:23:34 +00:00
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'.
```
This commit is contained in:
@@ -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"},
|
||||
|
||||
Reference in New Issue
Block a user