From caca209c8f14145b88cee2f4fac44fd62afaaef0 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 21 Feb 2024 15:35:38 +0500 Subject: [PATCH] BBIM - update related representations on assigning style to material --- .../blenderbim/bim/module/material/operator.py | 13 +++++++------ src/blenderbim/blenderbim/tool/material.py | 13 +++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/material/operator.py b/src/blenderbim/blenderbim/bim/module/material/operator.py index 32723ed46b..45ccae09c2 100644 --- a/src/blenderbim/blenderbim/bim/module/material/operator.py +++ b/src/blenderbim/blenderbim/bim/module/material/operator.py @@ -750,14 +750,14 @@ class EditMaterialStyle(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props = bpy.context.scene.BIMMaterialProperties - material = tool.Ifc.get().by_id(props.active_material_id) - style = tool.Ifc.get().by_id(int(props.styles)) - context = tool.Ifc.get().by_id(int(props.contexts)) - ifcopenshell.api.run( - "style.assign_material_style", tool.Ifc.get(), material=material, style=style, context=context - ) + ifc_file = tool.Ifc.get() + material = ifc_file.by_id(props.active_material_id) + style = ifc_file.by_id(int(props.styles)) + context = ifc_file.by_id(int(props.contexts)) + ifcopenshell.api.run("style.assign_material_style", ifc_file, material=material, style=style, context=context) tool.Material.disable_editing_material() core.load_materials(tool.Material, props.material_type) + tool.Material.update_elements_using_material(material) class UnassignMaterialStyle(bpy.types.Operator, tool.Ifc.Operator): @@ -776,3 +776,4 @@ class UnassignMaterialStyle(bpy.types.Operator, tool.Ifc.Operator): "style.unassign_material_style", tool.Ifc.get(), material=material, style=style, context=context ) core.load_materials(tool.Material, props.material_type) + tool.Material.update_elements_using_material(material) diff --git a/src/blenderbim/blenderbim/tool/material.py b/src/blenderbim/blenderbim/tool/material.py index ea790996ee..70c64eeb83 100644 --- a/src/blenderbim/blenderbim/tool/material.py +++ b/src/blenderbim/blenderbim/tool/material.py @@ -223,3 +223,16 @@ class Material(blenderbim.core.tool.Material): assinged_material = cls.get_material(element) material_profile = tool.Ifc.run("material.add_profile", profile_set=assinged_material, material=material) return material_profile + + @classmethod + def update_elements_using_material(cls, material): + # update elements that are using this material + elements = ifcopenshell.util.element.get_elements_by_material(tool.Ifc.get(), material) + # filter only unique representations to avoid reloading same representations multiple times + meshes_to_objects = dict() + for e in elements: + obj = tool.Ifc.get_object(e) + mesh = obj.data + meshes_to_objects[mesh] = obj + for obj in meshes_to_objects.values(): + tool.Geometry.reload_representation(obj)