From 5fb7e6e375ebe4cc49342f3ef3ebce9a0bc0879f Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 3 Jun 2024 12:37:56 +0500 Subject: [PATCH] resource.remove_resource - fix issue removing resources in ifc2x3 --- .../api/resource/remove_resource.py | 5 +++-- .../test/api/resource/test_remove_resource.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/ifcopenshell-python/test/api/resource/test_remove_resource.py diff --git a/src/ifcopenshell-python/ifcopenshell/api/resource/remove_resource.py b/src/ifcopenshell-python/ifcopenshell/api/resource/remove_resource.py index e5356a9dd9..bf5c46e6f7 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/resource/remove_resource.py +++ b/src/ifcopenshell-python/ifcopenshell/api/resource/remove_resource.py @@ -74,8 +74,9 @@ def remove_resource(file: ifcopenshell.file, resource: ifcopenshell.entity_insta file.remove(inverse) if history: ifcopenshell.util.element.remove_deep2(file, history) - if settings["resource"].Usage: - file.remove(settings["resource"].Usage) + # Usage was added in IFC4. + if usage := getattr(settings["resource"], "Usage", None): + file.remove(usage) if settings["resource"].BaseQuantity: ifcopenshell.api.run( "resource.remove_resource_quantity", diff --git a/src/ifcopenshell-python/test/api/resource/test_remove_resource.py b/src/ifcopenshell-python/test/api/resource/test_remove_resource.py new file mode 100644 index 0000000000..514c8bc16f --- /dev/null +++ b/src/ifcopenshell-python/test/api/resource/test_remove_resource.py @@ -0,0 +1,19 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2024 Dion Moult +# +# This file is part of IfcOpenShell. +# +# IfcOpenShell is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# IfcOpenShell is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with IfcOpenShell. If not, see . + +# remove_resource tests is partially covered by test_add_resource_quantity.