mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 13:46:54 +00:00
New IfcOpenShell utility to get instances of an element type easily
This commit is contained in:
@@ -78,6 +78,12 @@ def get_type(element):
|
|||||||
return relationship.RelatingType
|
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):
|
def get_material(element, should_skip_usage=False):
|
||||||
if hasattr(element, "HasAssociations") and element.HasAssociations:
|
if hasattr(element, "HasAssociations") and element.HasAssociations:
|
||||||
for relationship in element.HasAssociations:
|
for relationship in element.HasAssociations:
|
||||||
|
|||||||
@@ -136,6 +136,14 @@ class TestGetTypeIFC2X3(test.bootstrap.IFC2X3):
|
|||||||
assert subject.get_type(element_type) == element_type
|
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):
|
class TestGetMaterial(test.bootstrap.IFC4):
|
||||||
def test_getting_the_material_of_a_product(self):
|
def test_getting_the_material_of_a_product(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
|
|||||||
Reference in New Issue
Block a user