New IfcOpenShell utility to get instances of an element type easily

This commit is contained in:
Dion Moult
2021-11-08 20:40:49 +11:00
parent 246460dec4
commit 4fdcb87a28
2 changed files with 14 additions and 0 deletions
@@ -78,6 +78,12 @@ def get_type(element):
return relationship.RelatingType
def get_types(type):
for rel in getattr(type, "Types", []):
return rel.RelatedObjects
return []
def get_material(element, should_skip_usage=False):
if hasattr(element, "HasAssociations") and element.HasAssociations:
for relationship in element.HasAssociations:
@@ -136,6 +136,14 @@ class TestGetTypeIFC2X3(test.bootstrap.IFC2X3):
assert subject.get_type(element_type) == element_type
class TestGetTypes(test.bootstrap.IFC4):
def test_getting_the_type_of_a_product(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=element_type)
assert subject.get_types(element_type) == (element,)
class TestGetMaterial(test.bootstrap.IFC4):
def test_getting_the_material_of_a_product(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")