Fix potential instability when assigning types and synchronising Blender geometry

This commit is contained in:
Dion Moult
2021-05-18 14:36:12 +10:00
parent 30c31d694a
commit e6bf32b832
7 changed files with 69 additions and 78 deletions
@@ -14,11 +14,8 @@ class Data:
cls.products[product_id] = []
product = file.by_id(product_id)
representations = []
if product.is_a("IfcProduct"):
if product.Representation:
representations = product.Representation.Representations
else:
representations = []
if product.is_a("IfcProduct") and product.Representation:
representations = product.Representation.Representations
elif product.is_a("IfcTypeProduct"):
representations = [rm.MappedRepresentation for rm in product.RepresentationMaps or []]
for representation in representations:
@@ -52,3 +52,30 @@ class Usecase:
"RelatingType": self.settings["relating_type"],
}
)
self.map_representations()
def map_representations(self):
if not self.settings["relating_type"].RepresentationMaps:
return
representations = []
if self.settings["related_object"].Representation:
representations = self.settings["related_object"].Representation.Representations
for representation in representations:
# TODO: check if this is right? Surely this can be a single usecase?
ifcopenshell.api.run(
"geometry.unassign_representation",
self.file,
**{"product": self.settings["related_object"], "representation": representation}
)
ifcopenshell.api.run("geometry.remove_representation", self.file, **{"representation": representation})
for representation_map in self.settings["relating_type"].RepresentationMaps:
representation = representation_map.MappedRepresentation
result = ifcopenshell.api.run(
"geometry.map_representation", self.file, **{"representation": representation}
)
ifcopenshell.api.run(
"geometry.assign_representation",
self.file,
**{"product": self.settings["related_object"], "representation": result}
)