Skip to content

Commit 4fdcb87

Browse files
committed
New IfcOpenShell utility to get instances of an element type easily
1 parent 246460d commit 4fdcb87

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/ifcopenshell-python/ifcopenshell/util/element.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ def get_type(element):
7878
return relationship.RelatingType
7979

8080

81+
def get_types(type):
82+
for rel in getattr(type, "Types", []):
83+
return rel.RelatedObjects
84+
return []
85+
86+
8187
def get_material(element, should_skip_usage=False):
8288
if hasattr(element, "HasAssociations") and element.HasAssociations:
8389
for relationship in element.HasAssociations:

src/ifcopenshell-python/test/util/test_element.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ def test_getting_the_type_of_a_product(self):
136136
assert subject.get_type(element_type) == element_type
137137

138138

139+
class TestGetTypes(test.bootstrap.IFC4):
140+
def test_getting_the_type_of_a_product(self):
141+
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
142+
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
143+
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=element_type)
144+
assert subject.get_types(element_type) == (element,)
145+
146+
139147
class TestGetMaterial(test.bootstrap.IFC4):
140148
def test_getting_the_material_of_a_product(self):
141149
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")

0 commit comments

Comments
 (0)