show error message removing material that is used in material sets

previously it wasn't showing anything when you would try to remove a material
This commit is contained in:
Andrej730
2024-02-21 15:54:30 +05:00
parent caca209c8f
commit d5feaaa1af
2 changed files with 9 additions and 3 deletions
@@ -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):
+5 -2
View File
@@ -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):