From 03793db75f3815a41ded7aff487588991544e3d4 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 26 Dec 2024 16:10:23 +0500 Subject: [PATCH] Keep IfcStore.path as empty string if file is not saved Previously it would get cwd value in that case as bpy.path.abspath("//") returns cwd if .blend is not saved. --- src/bonsai/bonsai/bim/ifc.py | 7 ++++--- src/bonsai/bonsai/tool/ifc.py | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/bonsai/bonsai/bim/ifc.py b/src/bonsai/bonsai/bim/ifc.py index c53756e753..5cf0df62e3 100644 --- a/src/bonsai/bonsai/bim/ifc.py +++ b/src/bonsai/bonsai/bim/ifc.py @@ -33,7 +33,7 @@ import bonsai.bim.handler import bonsai.tool as tool from pathlib import Path from bonsai.tool.brick import BrickStore -from typing import Set, Union, Optional, TypedDict, Callable, NotRequired +from typing import Set, Union, Optional, TypedDict, Callable, NotRequired, cast IFC_CONNECTED_TYPE = Union[bpy.types.Material, bpy.types.Object] @@ -105,8 +105,9 @@ class IfcStore: @staticmethod def get_file(): if IfcStore.file is None: - IfcStore.path = bpy.context.scene.BIMProperties.ifc_file - if not os.path.isabs(IfcStore.path): + IfcStore.path = cast(str, bpy.context.scene.BIMProperties.ifc_file) + # Interpret relative paths as relative to .blend file. + if IfcStore.path and not os.path.isabs(IfcStore.path): IfcStore.path = os.path.abspath(os.path.join(bpy.path.abspath("//"), IfcStore.path)) if IfcStore.path: try: diff --git a/src/bonsai/bonsai/tool/ifc.py b/src/bonsai/bonsai/tool/ifc.py index a8374584f4..ea5e49682d 100644 --- a/src/bonsai/bonsai/tool/ifc.py +++ b/src/bonsai/bonsai/tool/ifc.py @@ -58,6 +58,7 @@ class Ifc(bonsai.core.tool.Ifc): @classmethod def get_path(cls) -> str: + """Get absolute filepath to the IFC file, return empty string if file is not saved.""" return IfcStore.path @classmethod