From c33c19c483d04ee43cd6fa3fdbef8227588ba8eb Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 8 Jul 2024 14:24:11 +0500 Subject: [PATCH] Support renaming materials by double clicking them in materials ui Example - https://imgur.com/a/NXr6Ku2 Which is especially important for non-IfcMaterials as they currently don't have their own editing UI (besides when they are applied to some element). --- .../blenderbim/bim/module/material/prop.py | 12 +++++++++++- src/blenderbim/blenderbim/bim/module/material/ui.py | 8 +++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/material/prop.py b/src/blenderbim/blenderbim/bim/module/material/prop.py index 192f7e7085..5967b4d896 100644 --- a/src/blenderbim/blenderbim/bim/module/material/prop.py +++ b/src/blenderbim/blenderbim/bim/module/material/prop.py @@ -119,8 +119,18 @@ def get_contexts(self, context): return MaterialsData.data["contexts"] +def update_material_name(self: "Material", context: bpy.types.Context) -> None: + ifc_file = tool.Ifc.get() + name = self.name + material = ifc_file.by_id(self.ifc_definition_id) + if material.is_a("IfcMaterialLayerSet"): + material.LayerSetName = name + else: + material.Name = name + + class Material(PropertyGroup): - name: StringProperty(name="Name") + name: StringProperty(name="Name", update=update_material_name) ifc_definition_id: IntProperty(name="IFC Definition ID") is_category: BoolProperty(name="Is Category", default=False) is_expanded: BoolProperty(name="Is Expanded", default=False) diff --git a/src/blenderbim/blenderbim/bim/module/material/ui.py b/src/blenderbim/blenderbim/bim/module/material/ui.py index 884885cafa..7ba072d237 100644 --- a/src/blenderbim/blenderbim/bim/module/material/ui.py +++ b/src/blenderbim/blenderbim/bim/module/material/ui.py @@ -348,6 +348,9 @@ class BIM_PT_object_material(Panel): class BIM_UL_materials(UIList): def draw_item(self, context, layout, data, item, icon, active_data, active_propname): + mprops = context.scene.BIMMaterialProperties + material_type = mprops.material_type + if item: row = layout.row(align=True) @@ -363,7 +366,10 @@ class BIM_UL_materials(UIList): row.label(text=item.name) else: row.label(text="", icon="BLANK1") - row.label(text=item.name, icon="MATERIAL") + if material_type == "IfcMaterialList": + row.label(text=item.name, icon="MATERIAL") + else: + row.prop(item, "name", text="", icon="MATERIAL", emboss=False) row2 = row.row() row2.alignment = "RIGHT"