Rename library references from UI

Example - https://imgur.com/a/Ez99d1N
This commit is contained in:
Andrej730
2025-02-17 13:23:38 +05:00
parent 8f1446bfa4
commit 8c2d71b306
2 changed files with 14 additions and 3 deletions
+12 -1
View File
@@ -17,6 +17,7 @@
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
import bpy
import bonsai.tool as tool
from bonsai.bim.prop import StrProperty, Attribute
from bonsai.bim.module.library.data import LibrariesData
from bpy.types import PropertyGroup
@@ -37,8 +38,18 @@ def update_active_reference_index(self, context):
LibrariesData.is_loaded = False
def update_library_element_name(self: "LibraryReference", context: bpy.types.Context):
ifc_file = tool.Ifc.get()
element = ifc_file.by_id(self.ifc_definition_id)
previous_name = element.Name
if self.name == previous_name:
return
element.Name = self.name
LibrariesData.is_loaded = False
class LibraryReference(PropertyGroup):
name: StringProperty(name="Name")
name: StringProperty(name="Name", update=update_library_element_name)
ifc_definition_id: IntProperty(name="IFC Definition ID")
if TYPE_CHECKING:
+2 -2
View File
@@ -140,7 +140,7 @@ class BIM_UL_library_references(UIList):
):
if item:
row = layout.row(align=True)
row.label(text=item.name)
row.prop(item, "name", text="", emboss=False)
op = row.operator("bim.enable_editing_library_reference", text="", icon="GREASEPENCIL")
op.reference = item.ifc_definition_id
op = row.operator("bim.remove_library_reference", text="", icon="X")
@@ -153,6 +153,6 @@ class BIM_UL_object_library_references(UIList):
):
if item:
row = layout.row(align=True)
row.label(text=item.name)
row.prop(item, "name", text="", emboss=False)
op = row.operator("bim.assign_library_reference", text="", icon="ADD")
op.reference = item.ifc_definition_id