From 27b9709b78357f07cd5b9e58c2c50ba850581f22 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 9 Sep 2024 16:54:05 +0500 Subject: [PATCH] style.assign_representation_styles to support topology reprensentations #4038 --- .../api/style/assign_representation_styles.py | 6 ++++-- .../style/test_assign_representation_styles.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/style/assign_representation_styles.py b/src/ifcopenshell-python/ifcopenshell/api/style/assign_representation_styles.py index afa30cfb15..b9b43ee8d0 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/style/assign_representation_styles.py +++ b/src/ifcopenshell-python/ifcopenshell/api/style/assign_representation_styles.py @@ -121,10 +121,12 @@ class Usecase: replace_previous_same_type_style = self.settings["replace_previous_same_type_style"] for element in self.file.traverse(self.settings["shape_representation"]): - if not element.is_a("IfcShapeRepresentation"): + if not element.is_a("IfcShapeModel"): continue for item in element.Items: - if not item.is_a("IfcGeometricRepresentationItem"): + if not item.is_a("IfcGeometricRepresentationItem") and not item.is_a( + "IfcTopologicalRepresentationItem" + ): continue if self.settings["styles"]: # If there are more items than styles, fallback to using the last style diff --git a/src/ifcopenshell-python/test/api/style/test_assign_representation_styles.py b/src/ifcopenshell-python/test/api/style/test_assign_representation_styles.py index 1995417e31..9527813291 100644 --- a/src/ifcopenshell-python/test/api/style/test_assign_representation_styles.py +++ b/src/ifcopenshell-python/test/api/style/test_assign_representation_styles.py @@ -103,6 +103,21 @@ class TestAssignRepresentationStyles(test.bootstrap.IFC4): assert item.StyledByItem[0].Styles[0].Styles == (style2, style3) assert len(self.file.by_type("IfcStyledItem")) == 1 + def test_assign_style_to_topology_representation(self): + element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall") + product_shape = self.file.create_entity("IfcProductDefinitionShape") + element.Representation = product_shape + + representation = self.file.create_entity("IfcTopologyRepresentation") + item = self.file.create_entity("IfcFace") + representation.Items = [item] + + style = self.file.create_entity("IfcSurfaceStyle") + ifcopenshell.api.style.assign_representation_styles( + self.file, styles=[style], shape_representation=representation + ) + assert item.StyledByItem[0].Styles == (style,) + class TestAssignRepresentationStylesIFC2X3(test.bootstrap.IFC2X3): def test_run(self):