mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
If models linked using relative path - store path as relative to ifc, not blend
As now we do support storing the list of linked models in IFC.
This commit is contained in:
@@ -967,7 +967,11 @@ class LinkIfc(bpy.types.Operator):
|
|||||||
files: bpy.props.CollectionProperty(name="Files", type=bpy.types.OperatorFileListElement)
|
files: bpy.props.CollectionProperty(name="Files", type=bpy.types.OperatorFileListElement)
|
||||||
directory: bpy.props.StringProperty(subtype="DIR_PATH")
|
directory: bpy.props.StringProperty(subtype="DIR_PATH")
|
||||||
filter_glob: bpy.props.StringProperty(default="*.ifc", options={"HIDDEN"})
|
filter_glob: bpy.props.StringProperty(default="*.ifc", options={"HIDDEN"})
|
||||||
use_relative_path: bpy.props.BoolProperty(name="Use Relative Path", default=False)
|
use_relative_path: bpy.props.BoolProperty(
|
||||||
|
name="Use Relative Path",
|
||||||
|
description="Whether to store linked model path relative to the currently opened IFC file.",
|
||||||
|
default=False,
|
||||||
|
)
|
||||||
use_cache: bpy.props.BoolProperty(name="Use Cache", default=True)
|
use_cache: bpy.props.BoolProperty(name="Use Cache", default=True)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@@ -998,9 +1002,9 @@ class LinkIfc(bpy.types.Operator):
|
|||||||
self.report({"INFO"}, "Can't link the current .blend file")
|
self.report({"INFO"}, "Can't link the current .blend file")
|
||||||
continue
|
continue
|
||||||
new = context.scene.BIMProjectProperties.links.add()
|
new = context.scene.BIMProjectProperties.links.add()
|
||||||
if self.use_relative_path:
|
if self.use_relative_path and (ifc_filepath := tool.Ifc.get_path()):
|
||||||
try:
|
try:
|
||||||
filepath = filepath.relative_to(bpy.path.abspath("//"))
|
filepath = filepath.relative_to(Path(ifc_filepath).parent)
|
||||||
except:
|
except:
|
||||||
pass # Perhaps on another drive or something
|
pass # Perhaps on another drive or something
|
||||||
# Store link paths as posix for cross-platform.
|
# Store link paths as posix for cross-platform.
|
||||||
@@ -1088,7 +1092,7 @@ class LoadLink(bpy.types.Operator):
|
|||||||
filepath_: Path
|
filepath_: Path
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
filepath = tool.Blender.ensure_blender_path_is_abs(Path(self.filepath))
|
filepath = Path(tool.Ifc.resolve_uri(self.filepath))
|
||||||
self.filepath_ = filepath
|
self.filepath_ = filepath
|
||||||
if filepath.suffix.lower().endswith(".blend"):
|
if filepath.suffix.lower().endswith(".blend"):
|
||||||
self.link_blend(filepath)
|
self.link_blend(filepath)
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ class Ifc(bonsai.core.tool.Ifc):
|
|||||||
return (uri if not uri else os.path.join(ifc_path, uri)).replace("\\", "/")
|
return (uri if not uri else os.path.join(ifc_path, uri)).replace("\\", "/")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_relative_uri(cls, uri):
|
def get_relative_uri(cls, uri: str) -> str:
|
||||||
if not os.path.isabs(uri):
|
if not os.path.isabs(uri):
|
||||||
return uri
|
return uri
|
||||||
ifc_path = cls.get_path()
|
ifc_path = cls.get_path()
|
||||||
|
|||||||
Reference in New Issue
Block a user