Fix material unassignment greedy purging bug, and auto assign usages of typed layer / profile sets.

This commit is contained in:
Dion Moult
2021-05-30 21:03:19 +10:00
parent 0b6f3113a7
commit c7ba643ef7
3 changed files with 35 additions and 3 deletions
@@ -1,4 +1,5 @@
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.util.element
@@ -10,6 +11,9 @@ class Usecase:
self.settings[key] = value
def execute(self):
material = ifcopenshell.util.element.get_material(self.settings["product"])
if material:
ifcopenshell.api.run("material.unassign_material", self.file, product=self.settings["product"])
if self.settings["type"] == "IfcMaterial":
self.assign_ifc_material()
elif self.settings["type"] == "IfcMaterialConstituentSet":
@@ -9,6 +9,15 @@ class Usecase:
self.settings[key] = value
def execute(self):
for association in self.settings["product"].HasAssociations:
if association.is_a("IfcRelAssociatesMaterial"):
self.file.remove(association)
for rel in self.settings["product"].HasAssociations:
if rel.is_a("IfcRelAssociatesMaterial"):
if rel.RelatingMaterial.is_a("IfcMaterialLayerSetUsage") or rel.RelatingMaterial.is_a(
"IfcMaterialProfileSetUsage"
):
self.file.remove(rel.RelatingMaterial)
if len(rel.RelatedObjects) == 1:
self.file.remove(rel)
continue
related_objects = set(rel.RelatedObjects)
related_objects.remove(self.settings["product"])
rel.RelatedObjects = list(related_object)