diff --git a/src/blenderbim/blenderbim/bim/module/material/operator.py b/src/blenderbim/blenderbim/bim/module/material/operator.py index 45ccae09c2..da600d4a6c 100644 --- a/src/blenderbim/blenderbim/bim/module/material/operator.py +++ b/src/blenderbim/blenderbim/bim/module/material/operator.py @@ -151,7 +151,10 @@ class RemoveMaterial(bpy.types.Operator, tool.Ifc.Operator): material: bpy.props.IntProperty() def _execute(self, context): - core.remove_material(tool.Ifc, tool.Material, tool.Style, material=tool.Ifc.get().by_id(self.material)) + res = core.remove_material(tool.Ifc, tool.Material, tool.Style, material=tool.Ifc.get().by_id(self.material)) + if not res: + self.report({"ERROR"}, "Material is used in material sets and cannot be removed.") + return {"CANCELLED"} class RemoveMaterialSet(bpy.types.Operator, tool.Ifc.Operator): diff --git a/src/blenderbim/blenderbim/core/material.py b/src/blenderbim/blenderbim/core/material.py index debf31c80d..ba1a19a1b0 100644 --- a/src/blenderbim/blenderbim/core/material.py +++ b/src/blenderbim/blenderbim/core/material.py @@ -43,9 +43,11 @@ def add_material_set(ifc, material, set_type=None): return ifc_material -def remove_material(ifc, material_tool, style, material=None): +def remove_material(ifc, material_tool, style, material=None) -> bool: + """returns True after deleting False,\n + returns False if material used in material sets and cannot be removed""" if material_tool.is_material_used_in_sets(material): - return + return False obj = ifc.get_object(material) ifc.unlink(element=material) ifc.run("material.remove_material", material=material) @@ -53,6 +55,7 @@ def remove_material(ifc, material_tool, style, material=None): material_tool.delete_object(obj) if material_tool.is_editing_materials(): material_tool.import_material_definitions(material_tool.get_active_material_type()) + return True def remove_material_set(ifc, material_tool, material=None):