From d66dd1be185585ed36f214ff9bcdc640ba6548f9 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 21 Jul 2025 16:36:24 +0500 Subject: [PATCH] Button that allows changing linked ifc project filepath Example - https://files.catbox.moe/usc5cu.png --- src/bonsai/bonsai/bim/module/project/ui.py | 2 ++ src/bonsai/bonsai/bim/operator.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/project/ui.py b/src/bonsai/bonsai/bim/module/project/ui.py index 55585d324b..88164e86c6 100644 --- a/src/bonsai/bonsai/bim/module/project/ui.py +++ b/src/bonsai/bonsai/bim/module/project/ui.py @@ -615,6 +615,8 @@ class BIM_UL_links(UIList): op.filepath = item.name else: row.prop(item, "name", text="") + op = row.operator("bim.select_uri_attribute", text="", icon="FILE_FOLDER") + op.attribute_data_path = tool.Blender.get_full_data_path(item, "name") op = row.operator("bim.load_link", text="", icon="LINKED") op.filepath = item.name op = row.operator("bim.unlink_ifc", text="", icon="X") diff --git a/src/bonsai/bonsai/bim/operator.py b/src/bonsai/bonsai/bim/operator.py index 85de0534ee..6a7ce88c93 100644 --- a/src/bonsai/bonsai/bim/operator.py +++ b/src/bonsai/bonsai/bim/operator.py @@ -157,7 +157,7 @@ class SelectURIAttribute(bpy.types.Operator, ImportHelper): bl_options = {"REGISTER", "UNDO"} bl_description = "Select a local file" attribute_data_path: bpy.props.StringProperty(name="Data Path") # pyright: ignore[reportRedeclaration] - """Full data path to Attribute.""" + """Full data path to `Attribute`/string property.""" use_relative_path: bpy.props.BoolProperty( # pyright: ignore[reportRedeclaration] name="Use Relative Path", default=False, @@ -168,8 +168,16 @@ class SelectURIAttribute(bpy.types.Operator, ImportHelper): use_relative_path: bool def execute(self, context): - attribute: Attribute = eval(self.attribute_data_path) - attribute.string_value = tool.Ifc.get_uri(self.filepath, use_relative_path=self.use_relative_path) + from bonsai.bim.prop import Attribute + + filepath = tool.Ifc.get_uri(self.filepath, use_relative_path=self.use_relative_path) + + attribute = eval(self.attribute_data_path) + if isinstance(attribute, Attribute): + attribute.string_value = filepath + else: + bpy_struct_path, _, attr_name = self.attribute_data_path.rpartition(".") + setattr(eval(bpy_struct_path), attr_name, filepath) return {"FINISHED"}