Removing contexts now also reassign to parent or remove references to the context.

This commit is contained in:
Dion Moult
2021-10-01 09:29:38 +10:00
parent a7a1616f9d
commit 42d321d553
3 changed files with 85 additions and 2 deletions
@@ -1,3 +1,6 @@
import ifcopenshell
class Usecase:
def __init__(self, file, **settings):
self.file = file
@@ -6,7 +9,23 @@ class Usecase:
self.settings[key] = value
def execute(self):
# TODO: this is a light remove only
for subcontext in self.settings["context"].HasSubContexts:
self.file.remove(subcontext)
ifcopenshell.api.run("context.remove_context", self.file, context=subcontext)
if getattr(self.settings["context"], "ParentContext", None):
new = self.settings["context"].ParentContext
for inverse in self.file.get_inverse(self.settings["context"]):
ifcopenshell.util.element.replace_attribute(inverse, self.settings["context"], new)
representations_in_context = self.settings["context"].RepresentationsInContext
has_coordinate_operation = []
if self.settings["context"].is_a("IfcGeometricRepresentationSubContext"):
has_coordinate_operation = self.settings["context"].HasCoordinateOperation
self.file.remove(self.settings["context"])
for element in representations_in_context:
ifcopenshell.api.run("geometry.remove_representation", self.file, representation=element)
for element in has_coordinate_operation:
ifcopenshell.util.element.remove_deep(self.file, element)