From 2699278ba3d9265c45703a4ab5b7f2d1e64b048b Mon Sep 17 00:00:00 2001 From: "Sigma Dimensions (Yass)" <79010126+myoualid@users.noreply.github.com> Date: Tue, 22 Aug 2023 19:34:47 +0100 Subject: [PATCH] api usecase to add a reference path to a metric objective --- .../api/constraint/add_metric_reference.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/ifcopenshell-python/ifcopenshell/api/constraint/add_metric_reference.py diff --git a/src/ifcopenshell-python/ifcopenshell/api/constraint/add_metric_reference.py b/src/ifcopenshell-python/ifcopenshell/api/constraint/add_metric_reference.py new file mode 100644 index 0000000000..072c71ecb0 --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/constraint/add_metric_reference.py @@ -0,0 +1,45 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 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 . + +import ifcopenshell + +class Usecase: + def __init__(self, file, metric=None, reference_path=None): + """ + Adds a chain of references to a metric. The reference path is a string of the form "attribute.attribute.attribute" + Used to reference a value of an attribute of an instance through a metric objective entity. + """ + self.file = file + self.settings = {"metric": metric, "reference_path": reference_path} + + def execute(self): + if self.settings["reference_path"]: + attributes = self.settings["reference_path"].split(".") + references_created = [] + for i in range(len(attributes)): + if i == 0: + reference = self.file.create_entity("IfcReference") + reference.AttributeIdentifier = attributes[i] + self.settings["metric"].ReferencePath = reference + references_created.append(reference) + else: + reference = self.file.create_entity("IfcReference") + reference.AttributeIdentifier = attributes[i] + references_created[i-1].InnerReference = reference + references_created.append(reference) + return references_created \ No newline at end of file