mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 02:47:48 +00:00
Generate functions for all API usecases for better static code features. See #2693.
This commit is contained in:
@@ -18,28 +18,26 @@
|
||||
|
||||
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
|
||||
def add_metric_reference(file, metric=None, reference_path=None) -> 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.
|
||||
"""
|
||||
settings = {"metric": metric, "reference_path": reference_path}
|
||||
|
||||
if settings["reference_path"]:
|
||||
attributes = settings["reference_path"].split(".")
|
||||
references_created = []
|
||||
for i in range(len(attributes)):
|
||||
if i == 0:
|
||||
reference = file.create_entity("IfcReference")
|
||||
reference.AttributeIdentifier = attributes[i]
|
||||
settings["metric"].ReferencePath = reference
|
||||
references_created.append(reference)
|
||||
else:
|
||||
reference = file.create_entity("IfcReference")
|
||||
reference.AttributeIdentifier = attributes[i]
|
||||
references_created[i - 1].InnerReference = reference
|
||||
references_created.append(reference)
|
||||
return references_created
|
||||
|
||||
Reference in New Issue
Block a user