From aedc1751b6db8ffc8e95ce0b3079f0b79c56fd8b Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 16 Oct 2021 16:55:06 +1100 Subject: [PATCH] Resolve #1802. Unlinking an object now also unlinks materials and styles too for convenience. --- .../blenderbim/bim/module/root/operator.py | 6 ++++++ src/blenderbim/pytest.ini | 1 + src/blenderbim/test/bim/feature/root.feature | 15 +++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 src/blenderbim/test/bim/feature/root.feature diff --git a/src/blenderbim/blenderbim/bim/module/root/operator.py b/src/blenderbim/blenderbim/bim/module/root/operator.py index 4d2e77f91f..bcd4b380d0 100644 --- a/src/blenderbim/blenderbim/bim/module/root/operator.py +++ b/src/blenderbim/blenderbim/bim/module/root/operator.py @@ -23,6 +23,8 @@ import ifcopenshell.util.schema import ifcopenshell.util.element import blenderbim.bim.handler import blenderbim.core.spatial +import blenderbim.core.style +import blenderbim.core.material import blenderbim.tool as tool from ifcopenshell.api.void.data import Data as VoidData from blenderbim.bim.ifc import IfcStore @@ -315,6 +317,10 @@ class UnlinkObject(bpy.types.Operator): for obj in objects: if obj.BIMObjectProperties.ifc_definition_id: IfcStore.unlink_element(obj=obj) + for material_slot in obj.material_slots: + if material_slot.material: + blenderbim.core.style.unlink_style(tool.Style, obj=material_slot.material) + blenderbim.core.material.unlink_material(tool.Material, obj=material_slot.material) if "Ifc" in obj.name and "/" in obj.name: obj.name = "/".join(obj.name.split("/")[1:]) return {"FINISHED"} diff --git a/src/blenderbim/pytest.ini b/src/blenderbim/pytest.ini index a4662b9470..90c1731b61 100644 --- a/src/blenderbim/pytest.ini +++ b/src/blenderbim/pytest.ini @@ -7,6 +7,7 @@ markers = owner project pset_template + root spatial style unit diff --git a/src/blenderbim/test/bim/feature/root.feature b/src/blenderbim/test/bim/feature/root.feature new file mode 100644 index 0000000000..aed40d3e2a --- /dev/null +++ b/src/blenderbim/test/bim/feature/root.feature @@ -0,0 +1,15 @@ +@root +Feature: Root + +Scenario: Unlink object + Given an empty IFC project + And I add a cube + And the object "Cube" is selected + And I add a material + And I set "scene.BIMRootProperties.ifc_class" to "IfcWall" + And I press "bim.assign_class" + And I press "bim.add_material" + When I press "bim.unlink_object(obj='IfcWall/Cube')" + Then the object "Cube" is not an IFC element + And the material "Material" is not an IFC material + And the material "Material" is not an IFC style