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.
This commit is contained in:
Andrej730
2024-12-26 16:10:23 +05:00
parent faa13a938d
commit 03793db75f
2 changed files with 5 additions and 3 deletions
+4 -3
View File
@@ -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:
+1
View File
@@ -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