Files
IfcOpenShell/src/ifcopenshell-python/ifcopenshell/api/constraint/remove_metric.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
2.4 KiB
Python
Raw Normal View History

# IfcOpenShell - IFC toolkit and geometry engine
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# 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 <http://www.gnu.org/licenses/>.
2024-05-09 14:18:36 +05:00
import ifcopenshell
2024-05-09 14:18:36 +05:00
def remove_metric(file: ifcopenshell.file, metric: ifcopenshell.entity_instance) -> None:
"""Remove a metric benchmark
Removes a metric benchmark and all of its associations to any products
and objectives.
2022-11-16 08:56:55 +09:00
:param metric: The IfcMetric you want to remove.
:type metric: ifcopenshell.entity_instance
:return: None
:rtype: None
2022-11-16 08:56:55 +09:00
Example:
2022-11-16 08:56:55 +09:00
.. code:: python
2023-01-10 10:16:28 +11:00
objective = ifcopenshell.api.constraint.add_objective(model)
metric = ifcopenshell.api.constraint.add_metric(model,
objective=objective)
ifcopenshell.api.constraint.remove_metric(model,
metric=metric)
"""
usecase = Usecase()
usecase.file = file
usecase.settings = {"metric": metric}
return usecase.execute()
2022-11-16 08:56:55 +09:00
class Usecase:
def execute(self):
2023-08-22 19:36:01 +01:00
if self.settings["metric"].ReferencePath:
reference = self.settings["metric"].ReferencePath
self.delete_reference(reference)
self.file.remove(self.settings["metric"])
for rel in self.file.by_type("IfcRelAssociatesConstraint"):
if not rel.RelatingConstraint:
history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
for resource_rel in self.file.by_type("IfcResourceConstraintRelationship"):
if not resource_rel.RelatingConstraint:
self.file.remove(resource_rel)
2023-08-22 19:36:01 +01:00
def delete_reference(self, reference):
if reference.InnerReference:
self.delete_reference(reference.InnerReference)
self.file.remove(reference)