mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Support resource level classifications in IfcOpenShell API
This commit is contained in:
@@ -25,20 +25,30 @@ class Usecase:
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
total_related_objects = 0
|
||||
for association in self.file.by_type("IfcRelAssociatesClassification"):
|
||||
if association.RelatingClassification == self.settings["reference"] and association.RelatedObjects:
|
||||
total_related_objects += len(association.RelatedObjects)
|
||||
related_objects = list(association.RelatedObjects)
|
||||
try:
|
||||
related_objects.remove(self.settings["product"])
|
||||
except:
|
||||
continue
|
||||
if len(related_objects):
|
||||
association.RelatedObjects = related_objects
|
||||
else:
|
||||
self.file.remove(association)
|
||||
if self.settings["product"].is_a("IfcRoot"):
|
||||
for rel in self.file.by_type("IfcRelAssociatesClassification"):
|
||||
if rel.RelatingClassification == self.settings["reference"] and rel.RelatedObjects:
|
||||
if self.settings["product"] in rel.RelatedObjects:
|
||||
related_objects = list(rel.RelatedObjects)
|
||||
related_objects.remove(self.settings["product"])
|
||||
if len(related_objects):
|
||||
rel.RelatedObjects = related_objects
|
||||
else:
|
||||
self.file.remove(rel)
|
||||
else:
|
||||
for rel in self.file.by_type("IfcExternalReferenceRelationship"):
|
||||
if rel.RelatingReference == self.settings["reference"] and rel.RelatedResourceObjects:
|
||||
if self.settings["product"] in rel.RelatedResourceObjects:
|
||||
related_objects = list(rel.RelatedResourceObjects)
|
||||
related_objects.remove(self.settings["product"])
|
||||
if len(related_objects):
|
||||
rel.RelatedResourceObjects = related_objects
|
||||
else:
|
||||
self.file.remove(rel)
|
||||
|
||||
# TODO: we only handle lightweight classifications here
|
||||
if total_related_objects == 1:
|
||||
if (
|
||||
not self.settings["reference"].ClassificationRefForObjects
|
||||
and not self.settings["reference"].ExternalReferenceForResources
|
||||
):
|
||||
self.file.remove(self.settings["reference"])
|
||||
|
||||
Reference in New Issue
Block a user