From a9f27fcf17f985d9409015d5fb13cfd9b100d2fc Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 10 Nov 2021 18:04:54 +1100 Subject: [PATCH] Fix bug #1854. Materials are now auto replaced in Blender when you assign a new IFC material. --- .../blenderbim/bim/module/model/product.py | 7 ++- .../test/bim/feature/material.feature | 43 +++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/model/product.py b/src/blenderbim/blenderbim/bim/module/model/product.py index 4d9c8c6abd..0f8f4bdeda 100644 --- a/src/blenderbim/blenderbim/bim/module/model/product.py +++ b/src/blenderbim/blenderbim/bim/module/model/product.py @@ -303,9 +303,9 @@ def regenerate_profile_usage(usecase_path, ifc_file, settings): def ensure_material_assigned(usecase_path, ifc_file, settings): if usecase_path == "material.assign_material": - if not settings.get("Material", None): + if not settings.get("material", None): return - elements = [self.settings["product"]] + elements = [settings["product"]] else: elements = [] for rel in ifc_file.by_type("IfcRelAssociatesMaterial"): @@ -331,4 +331,7 @@ def ensure_material_assigned(usecase_path, ifc_file, settings): if material[0].id() in object_material_ids: continue + if len(obj.data.materials) == 1: + obj.data.materials.clear() + obj.data.materials.append(IfcStore.get_element(material[0].id())) diff --git a/src/blenderbim/test/bim/feature/material.feature b/src/blenderbim/test/bim/feature/material.feature index 6ef85febbd..6516cb5c9a 100644 --- a/src/blenderbim/test/bim/feature/material.feature +++ b/src/blenderbim/test/bim/feature/material.feature @@ -31,3 +31,46 @@ Scenario: Unlink material And I press "bim.add_material" When I press "bim.unlink_material" Then the material "Material" is not an IFC material + +Scenario: Assign material - Assign a material + Given an empty IFC project + And I add a cube + And the object "Cube" is selected + And I set "scene.BIMRootProperties.ifc_class" to "IfcWall" + And I press "bim.assign_class" + And I press "bim.add_default_material" + When I set "active_object.BIMObjectMaterialProperties.material_type" to "IfcMaterial" + And I press "bim.assign_material" + Then the object "IfcWall/Cube" has the material "Default" + +Scenario: Assign material - Assign a material layer set + Given an empty IFC project + And I add a cube + And the object "Cube" is selected + And I set "scene.BIMRootProperties.ifc_class" to "IfcWall" + And I press "bim.assign_class" + And I add an empty + And the object "Empty" is selected + And I set "scene.BIMRootProperties.ifc_product" to "IfcElementType" + And I set "scene.BIMRootProperties.ifc_class" to "IfcWallType" + And I press "bim.assign_class" + And I press "bim.add_default_material" + When I set "active_object.BIMObjectMaterialProperties.material_type" to "IfcMaterialLayerSet" + And I press "bim.assign_material" + Then nothing happens + +Scenario: Assign material - Assign a material profile set + Given an empty IFC project + And I add a cube + And the object "Cube" is selected + And I set "scene.BIMRootProperties.ifc_class" to "IfcWall" + And I press "bim.assign_class" + And I add an empty + And the object "Empty" is selected + And I set "scene.BIMRootProperties.ifc_product" to "IfcElementType" + And I set "scene.BIMRootProperties.ifc_class" to "IfcWallType" + And I press "bim.assign_class" + And I press "bim.add_default_material" + When I set "active_object.BIMObjectMaterialProperties.material_type" to "IfcMaterialProfileSet" + And I press "bim.assign_material" + Then nothing happens