type.assign_type - support batching #4474

This commit is contained in:
Andrej730
2024-04-10 17:18:37 +05:00
parent ba4eb2a891
commit df4943205a
34 changed files with 308 additions and 162 deletions
@@ -648,7 +648,7 @@ efficient and implies that the type is interchangable (e.g. for maintenance).
# Assign our furniture occurrence to the type.
# That's it! The representation will automatically be mapped!
run("type.assign_type", model, related_object=element, relating_type=element_type)
run("type.assign_type", model, related_objects=[element], relating_type=element_type)
Material layer sets
-------------------
@@ -693,7 +693,7 @@ responsibility to make sure the geometry is correct.
ifcopenshell.api.run("geometry.edit_object_placement", model, product=wall)
# The wall is a WAL01 wall type. The material layer set is inherited.
ifcopenshell.api.run("type.assign_type", model, related_object=wall, relating_type=wall_type)
ifcopenshell.api.run("type.assign_type", model, related_objects=[wall], relating_type=wall_type)
# It's now our responsibility to create a compatible representation.
# Notice how our thickness of 0.118 must equal .013 + .092 + .013 from our type
@@ -749,7 +749,7 @@ responsibility to make sure the geometry is correct.
ifcopenshell.api.run("geometry.edit_object_placement", model, product=beam)
# The beam is a B1 beam type. The material profile set is inherited.
ifcopenshell.api.run("type.assign_type", model, related_object=beam, relating_type=beam_type)
ifcopenshell.api.run("type.assign_type", model, related_objects=[beam], relating_type=beam_type)
# It's now our responsibility to create a compatible representation.
# Notice how we reuse our profile instead of creating a new profile.
@@ -73,6 +73,9 @@ ARGUMENTS_DEPRECATION = {
"nest.unassign_object": partial(
batching_argument_deprecation, prev_argument="related_object", new_argument="related_objects"
),
"type.assign_type": partial(
batching_argument_deprecation, prev_argument="related_object", new_argument="related_objects"
),
}
@@ -85,8 +85,8 @@ class Usecase:
# automatically inherit the material from the type.
bench1 = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcFurniture")
bench2 = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcFurniture")
ifcopenshell.api.run("type.assign_type", model, related_object=bench1, relating_type=bench_type)
ifcopenshell.api.run("type.assign_type", model, related_object=bench2, relating_type=bench_type)
ifcopenshell.api.run("type.assign_type", model, related_objects=[bench1], relating_type=bench_type)
ifcopenshell.api.run("type.assign_type", model, related_objects=[bench2], relating_type=bench_type)
# If we have a concrete wall, we should use a layer set. Again,
# let's start with a wall type, not occurrences.
@@ -106,7 +106,7 @@ class Usecase:
# Let's imagine an occurrence of this wall type.
wall = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
ifcopenshell.api.run("type.assign_type", model, related_object=wall, relating_type=wall_type)
ifcopenshell.api.run("type.assign_type", model, related_objects=[wall], relating_type=wall_type)
# Our wall occurrence needs to have a "set usage" which describes
# how the layers relate to a reference line (typically a 2D line
@@ -59,7 +59,7 @@ class Usecase:
# Let's imagine an occurrence of this wall type.
wall = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
ifcopenshell.api.run("type.assign_type", model, related_object=wall, relating_type=wall_type)
ifcopenshell.api.run("type.assign_type", model, related_objects=[wall], relating_type=wall_type)
# Our wall occurrence needs to have a "set usage" which describes
# how the layers relate to a reference line (typically a 2D line
@@ -204,7 +204,7 @@ class Usecase:
"type.assign_type",
self.file,
should_run_listeners=False,
related_object=element,
related_objects=[element],
relating_type=new_type,
should_map_representations=False,
)
@@ -19,11 +19,18 @@
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.util.element
from typing import Union
class Usecase:
def __init__(self, file, related_object=None, relating_type=None, should_map_representations=True):
"""Assigns a type to an occurrence of an object
def __init__(
self,
file: ifcopenshell.file,
related_objects: list[ifcopenshell.entity_instance],
relating_type: ifcopenshell.entity_instance,
should_map_representations=True,
):
"""Assigns a type to occurrences of an object
IFC supports the concept of occurrences and types. An occurrence is an
actual physical product in the real world: like a wall, a chair, a door,
@@ -83,8 +90,8 @@ class Usecase:
as-built or dilapidation models, where existing conditions are
ambiguous, unknown or are so bespoke as to have no logical type.
:param related_object: The IfcElement occurrence.
:type related_object: ifcopenshell.entity_instance.entity_instance
:param related_objects: The IfcElement occurrences.
:type related_objects: list[ifcopenshell.entity_instance.entity_instance]
:param relating_type: The IfcElementType type.
:type relating_type: ifcopenshell.entity_instance.entity_instance
:param should_map_representations: If a type has a representation map,
@@ -93,7 +100,8 @@ class Usecase:
yourself. In this scenario, you may set this to False.
:type should_map_representations: bool
:return: The IfcRelDefinesByType relationship
:rtype: ifcopenshell.entity_instance.entity_instance
or `None` if `related_objects` was empty list.
:rtype: Union[ifcopenshell.entity_instance.entity_instance, None]
Example:
@@ -111,7 +119,7 @@ class Usecase:
# had a representation, the furniture occurrence will also now have
# the exact same representation. This is highly efficient as you
# don't need to define the representation for every occurrence.
ifcopenshell.api.run("type.assign_type", model, related_object=furniture, relating_type=furniture_type)
ifcopenshell.api.run("type.assign_type", model, related_objects=[furniture], relating_type=furniture_type)
# Let's imagine a parametric material layer set
wall_type = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWallType", name="WAL01")
@@ -146,7 +154,7 @@ class Usecase:
wall = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
# The wall is a WAL01 wall type.
ifcopenshell.api.run("type.assign_type", model, related_object=wall, relating_type=wall_type)
ifcopenshell.api.run("type.assign_type", model, related_objects=[wall], relating_type=wall_type)
# A bit of preparation, let's create some geometric contexts since
# we want to create some geometry for our wall.
@@ -167,81 +175,101 @@ class Usecase:
"""
self.file = file
self.settings = {
"related_object": related_object,
"related_objects": related_objects,
"relating_type": relating_type,
"should_map_representations": should_map_representations,
}
def execute(self):
if self.file.schema == "IFC2X3":
is_typed_by = None
is_defined_by = self.settings["related_object"].IsDefinedBy
for rel in is_defined_by:
if rel.is_a("IfcRelDefinesByType"):
is_typed_by = [rel]
break
types = self.settings["relating_type"].ObjectTypeOf
else:
is_typed_by = self.settings["related_object"].IsTypedBy
types = self.settings["relating_type"].Types
if types and is_typed_by == types:
def execute(self) -> Union[ifcopenshell.entity_instance, None]:
if not self.settings["related_objects"]:
return
if is_typed_by:
related_objects = list(is_typed_by[0].RelatedObjects)
related_objects.remove(self.settings["related_object"])
if related_objects:
is_typed_by[0].RelatedObjects = related_objects
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": is_typed_by[0]})
related_objects = set(self.settings["related_objects"])
relating_type = self.settings["relating_type"]
ifc2x3 = self.file.schema == "IFC2X3"
related_objects = set(self.settings["related_objects"])
relating_type = self.settings["relating_type"]
if ifc2x3:
types = next(iter(relating_type.ObjectTypeOf), None)
else:
types = next(iter(relating_type.Types), None)
previous_types_rels: set[ifcopenshell.entity_instance] = set()
objects_without_types: list[ifcopenshell.entity_instance] = []
objects_with_types: list[ifcopenshell.entity_instance] = []
# check if there is anything to change
for object in related_objects:
if ifc2x3:
object_rel = next((i for i in object.IsDefinedBy if i.is_a("IfcRelDefinesByType")), None)
else:
history = is_typed_by[0].OwnerHistory
self.file.remove(is_typed_by[0])
object_rel = next(iter(object.IsTypedBy), None)
if object_rel is None:
objects_without_types.append(object)
continue
# either is_nested_by is None or product is part of different rel
if object_rel != types:
previous_types_rels.add(object_rel)
objects_with_types.append(object)
objects_to_change = objects_without_types + objects_with_types
# nothing to change
if not objects_to_change:
return types
# unassign from previous types
for is_typed_by in previous_types_rels:
cur_related_objects = set(is_typed_by.RelatedObjects) - related_objects
if cur_related_objects:
is_typed_by.RelatedObjects = list(cur_related_objects)
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": is_typed_by})
else:
history = is_typed_by.OwnerHistory
self.file.remove(is_typed_by)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
# assign objects to a new type
if types:
related_objects = list(types[0].RelatedObjects)
related_objects.append(self.settings["related_object"])
types[0].RelatedObjects = related_objects
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": types[0]})
types.RelatedObjects = list(set(types.RelatedObjects) | related_objects)
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": types})
else:
types = self.file.create_entity(
"IfcRelDefinesByType",
**{
"GlobalId": ifcopenshell.guid.new(),
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
"RelatedObjects": [self.settings["related_object"]],
"RelatingType": self.settings["relating_type"],
}
"RelatedObjects": list(related_objects),
"RelatingType": relating_type,
},
)
if self.settings["should_map_representations"]:
if getattr(self.settings["relating_type"], "RepresentationMaps", None):
ifcopenshell.api.run(
"type.map_type_representations",
self.file,
related_object=self.settings["related_object"],
relating_type=self.settings["relating_type"],
)
self.map_material_usages()
if getattr(relating_type, "RepresentationMaps", None):
for related_object in related_objects:
ifcopenshell.api.run(
"type.map_type_representations",
self.file,
related_object=related_object,
relating_type=relating_type,
)
self.map_material_usages(related_objects)
return types
def map_material_usages(self):
def map_material_usages(self, related_objects: set[ifcopenshell.entity_instance]) -> None:
type_material = ifcopenshell.util.element.get_material(self.settings["relating_type"])
if not type_material:
return
if type_material.is_a("IfcMaterialLayerSet"):
ifcopenshell.api.run(
"material.assign_material",
self.file,
product=self.settings["related_object"],
type="IfcMaterialLayerSetUsage",
)
elif type_material.is_a("IfcMaterialProfileSet"):
ifcopenshell.api.run(
"material.assign_material",
self.file,
product=self.settings["related_object"],
type="IfcMaterialProfileSetUsage",
)
ifc_class = type_material.is_a()
if ifc_class in ("IfcMaterialLayerSet", "IfcMaterialProfileSet"):
for related_object in related_objects:
ifcopenshell.api.run(
"material.assign_material",
self.file,
product=related_object,
type=f"{ifc_class}Usage",
)
@@ -60,7 +60,7 @@ class Usecase:
# furniture type has no representation, so the furniture may also
# have no representation, or any arbitrary representation that may
# vary from occurrence to occurrence.
ifcopenshell.api.run("type.assign_type", model, related_object=furniture, relating_type=furniture_type)
ifcopenshell.api.run("type.assign_type", model, related_objects=[furniture], relating_type=furniture_type)
# A bit of preparation, let's create some geometric contexts since
# we want to create some geometry for our furniture type.
@@ -42,7 +42,7 @@ class Usecase:
furniture = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcFurniture")
# Assign the furniture to the furniture type.
ifcopenshell.api.run("type.assign_type", model, related_object=furniture, relating_type=furniture_type)
ifcopenshell.api.run("type.assign_type", model, related_objects=[furniture], relating_type=furniture_type)
# Change our mind. Maybe it's a different type?
ifcopenshell.api.run("type.unassign_type", model, related_object=furniture)
@@ -47,7 +47,7 @@ class TestAssignRepresentation(test.bootstrap.IFC4):
def test_assigning_to_a_type_will_map_representations_to_instances(self):
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
walltype = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", self.file, related_object=wall, relating_type=walltype)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[wall], relating_type=walltype)
context = self.file.createIfcGeometricRepresentationContext()
rep = self.file.createIfcShapeRepresentation(ContextOfItems=context)
rep2 = self.file.createIfcShapeRepresentation(ContextOfItems=context)
@@ -69,7 +69,7 @@ class TestAssignRepresentation(test.bootstrap.IFC4):
ifcopenshell.api.run("geometry.assign_representation", self.file, product=walltype, representation=rep)
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("type.assign_type", self.file, related_object=wall, relating_type=walltype)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[wall], relating_type=walltype)
ifcopenshell.api.run("geometry.assign_representation", self.file, product=wall, representation=rep2)
assert wall.Representation.Representations[0].RepresentationType == "MappedRepresentation"
@@ -84,7 +84,7 @@ class TestAssignRepresentation(test.bootstrap.IFC4):
rep = self.file.createIfcShapeRepresentation(ContextOfItems=context)
walltype = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("type.assign_type", self.file, related_object=wall, relating_type=walltype)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[wall], relating_type=walltype)
ifcopenshell.api.run("geometry.assign_representation", self.file, product=wall, representation=rep)
assert wall.Representation.Representations[0].RepresentationType != "MappedRepresentation"
assert wall.Representation.Representations[0] == rep
@@ -48,7 +48,7 @@ class TestAssignMaterial(test.bootstrap.IFC4):
def test_assign_type_material_layer_set_and_element_layer_set_usage(self):
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
ifcopenshell.api.run("material.assign_material", self.file, product=element_type, type="IfcMaterialLayerSet")
ifcopenshell.api.run("material.assign_material", self.file, product=element, type="IfcMaterialLayerSetUsage")
@@ -69,7 +69,7 @@ class TestAssignMaterial(test.bootstrap.IFC4):
def test_assign_type_material_profile_set_and_element_profile_set_usage(self):
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
ifcopenshell.api.run("material.assign_material", self.file, product=element_type, type="IfcMaterialProfileSet")
ifcopenshell.api.run("material.assign_material", self.file, product=element, type="IfcMaterialProfileSetUsage")
@@ -62,7 +62,7 @@ class TestUnassignMaterial(test.bootstrap.IFC4):
def test_unassign_material_layer_set_usage_from_element(self):
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
ifcopenshell.api.run("material.assign_material", self.file, product=element_type, type="IfcMaterialLayerSet")
ifcopenshell.api.run("material.assign_material", self.file, product=element, type="IfcMaterialLayerSetUsage")
@@ -78,8 +78,8 @@ class TestUnassignMaterial(test.bootstrap.IFC4):
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", self.file, related_object=element2, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element2], relating_type=element_type)
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
ifcopenshell.api.run("material.assign_material", self.file, product=element_type, type="IfcMaterialLayerSet")
rel = ifcopenshell.api.run(
@@ -114,7 +114,7 @@ class TestUnassignMaterial(test.bootstrap.IFC4):
def test_unassign_material_profile_set_usage_from_element(self):
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
ifcopenshell.api.run("material.assign_material", self.file, product=element_type, type="IfcMaterialProfileSet")
ifcopenshell.api.run("material.assign_material", self.file, product=element, type="IfcMaterialProfileSetUsage")
@@ -88,7 +88,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
element_type = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
element_type2 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", library, related_object=element, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", library, related_objects=[element], relating_type=element_type)
material = ifcopenshell.api.run("material.add_material", library, name="Material")
ifcopenshell.api.run("material.assign_material", library, product=element, material=material)
ifcopenshell.api.run("material.assign_material", library, product=element_type, material=material)
@@ -186,7 +186,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
element_type.RepresentationMaps = [library.createIfcRepresentationMap(MappedRepresentation=mapped_rep)]
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
ifcopenshell.api.run("type.assign_type", library, related_object=element, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", library, related_objects=[element], relating_type=element_type)
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element)
assert len(self.file.by_type("IfcStyledItem")) == 1
@@ -356,7 +356,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
library = ifcopenshell.api.run("project.create_file")
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
element_type = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", library, related_object=element, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", library, related_objects=[element], relating_type=element_type)
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element)
assert ifcopenshell.util.element.get_type(self.file.by_type("IfcWall")[0]).is_a("IfcWallType")
@@ -366,9 +366,9 @@ class TestAppendAsset(test.bootstrap.IFC4):
element2 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
element3 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
element_type = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", library, related_object=element, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", library, related_object=element2, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", library, related_object=element3, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", library, related_objects=[element], relating_type=element_type)
ifcopenshell.api.run("type.assign_type", library, related_objects=[element2], relating_type=element_type)
ifcopenshell.api.run("type.assign_type", library, related_objects=[element3], relating_type=element_type)
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element)
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element2)
assert len(ifcopenshell.util.element.get_types(self.file.by_type("IfcWallType")[0])) == 2
@@ -387,7 +387,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
element_type = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
element_type2 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", library, related_object=element, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", library, related_objects=[element], relating_type=element_type)
material = ifcopenshell.api.run("material.add_material", library, name="Material")
ifcopenshell.api.run("material.assign_material", library, product=element, material=material)
ifcopenshell.api.run("material.assign_material", library, product=element_type, material=material)
@@ -419,7 +419,7 @@ class TestAppendAssetIFC2X3(test.bootstrap.IFC2X3):
library = ifcopenshell.api.run("project.create_file", version="IFC2X3")
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
element_type = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", library, related_object=element, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", library, related_objects=[element], relating_type=element_type)
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element)
assert ifcopenshell.util.element.get_type(self.file.by_type("IfcWall")[0]).is_a("IfcWallType")
@@ -429,9 +429,9 @@ class TestAppendAssetIFC2X3(test.bootstrap.IFC2X3):
element2 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
element3 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
element_type = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", library, related_object=element, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", library, related_object=element2, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", library, related_object=element3, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", library, related_objects=[element], relating_type=element_type)
ifcopenshell.api.run("type.assign_type", library, related_objects=[element2], relating_type=element_type)
ifcopenshell.api.run("type.assign_type", library, related_objects=[element3], relating_type=element_type)
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element)
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element2)
assert len(ifcopenshell.util.element.get_types(self.file.by_type("IfcWallType")[0])) == 2
@@ -210,7 +210,7 @@ class TestCopyClass(test.bootstrap.IFC4):
def test_copying_a_type_and_purging_type_relationships(self):
type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=type)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=type)
new = ifcopenshell.api.run("root.copy_class", self.file, product=type)
assert not new.Types
@@ -54,9 +54,9 @@ class TestReassignClass(test.bootstrap.IFC4):
def test_reassign_class_for_type_occurrences(self):
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element1, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element1], relating_type=element_type)
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element2, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element2], relating_type=element_type)
element_type = ifcopenshell.api.run(
"root.reassign_class", self.file, product=element_type, ifc_class="IfcSlabType"
@@ -74,9 +74,9 @@ class TestReassignClass(test.bootstrap.IFC4):
def test_reassigning_type_class_and_its_occurrences_classes_if_entity_was_typed(self):
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element1, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element1], relating_type=element_type)
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element2, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element2], relating_type=element_type)
element1 = ifcopenshell.api.run("root.reassign_class", self.file, product=element1, ifc_class="IfcSlab")
@@ -98,7 +98,7 @@ class TestRemoveProduct(test.bootstrap.IFC4):
context = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
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)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
rep_map = self.file.createIfcRepresentationMap(
MappingOrigin=self.file.createIfcAxis2Placement3D(),
MappedRepresentation=self.file.createIfcShapeRepresentation(
@@ -377,7 +377,7 @@ class TestRemoveProduct(test.bootstrap.IFC4):
def test_removing_all_type_relationships_of_an_element(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)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
ifcopenshell.api.run("root.remove_product", self.file, product=element)
assert not self.file.by_type("IfcRelDefinesByType")
assert self.file.by_type("IfcWallType")
@@ -386,8 +386,8 @@ class TestRemoveProduct(test.bootstrap.IFC4):
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element2 = 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=element1, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", self.file, related_object=element2, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element1], relating_type=element_type)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element2], relating_type=element_type)
ifcopenshell.api.run("root.remove_product", self.file, product=element_type)
assert not self.file.by_type("IfcRelDefinesByType")
assert self.file.by_type("IfcWall")
@@ -123,3 +123,11 @@ class TestTemporarySupportForDeprecatedAPIArguments(test.bootstrap.IFC4):
ifcopenshell.api.run("nest.assign_object", self.file, related_objects=[subelement1], relating_object=element)
ifcopenshell.api.run("nest.unassign_object", self.file, related_object=subelement1)
assert ifcopenshell.util.element.get_nest(subelement1) is None
@deprecation_check
def test_assigning_a_type(self):
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
rel = ifcopenshell.api.run("type.assign_type", self.file, related_object=element1, relating_type=element_type)
assert ifcopenshell.util.element.get_type(element1) == element_type
assert rel.is_a("IfcRelDefinesByType")
@@ -0,0 +1,70 @@
# IfcOpenShell - IFC toolkit and geometry engine
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of IfcOpenShell.
#
# IfcOpenShell is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IfcOpenShell is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.util.element
import pytest
class TestAssignType(test.bootstrap.IFC4):
def test_assigning_a_type(self):
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
rel = ifcopenshell.api.run(
"type.assign_type", self.file, related_objects=[element1, element2], relating_type=element_type
)
assert ifcopenshell.util.element.get_type(element1) == element_type
assert ifcopenshell.util.element.get_type(element2) == element_type
assert rel.is_a("IfcRelDefinesByType")
def test_doing_nothing_if_type_is_already_assigned(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_objects=[element], relating_type=element_type)
total_elements = len([e for e in self.file])
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
assert len([e for e in self.file]) == total_elements
def test_that_old_typing_relationships_are_updated_if_they_still_have_elements(self):
element_type1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element_type2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run(
"type.assign_type", self.file, related_objects=[element1, element2], relating_type=element_type1
)
rel = element1.IsDefinedBy[0] if self.file.schema == "IFC2X3" else element1.IsTypedBy[0]
assert len(rel.RelatedObjects) == 2
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element1], relating_type=element_type2)
assert len(rel.RelatedObjects) == 1
def test_that_old_typing_relationships_are_purged_if_no_more_elements_are_nested(self):
element_type1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element_type2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element1], relating_type=element_type1)
rel_id = (element1.IsDefinedBy[0] if self.file.schema == "IFC2X3" else element1.IsTypedBy[0]).id()
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element1], relating_type=element_type2)
with pytest.raises(RuntimeError):
self.file.by_id(rel_id)
class TestAssignTypeIFC2X3(test.bootstrap.IFC2X3, TestAssignType):
pass
@@ -24,7 +24,7 @@ class TestMapTypeRepresentations(test.bootstrap.IFC4):
def test_doing_nothing_if_the_type_has_no_representation_maps(self):
element = self.file.createIfcWall()
type = self.file.createIfcWallType()
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=type)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=type)
total_elements = len([e for e in self.file])
ifcopenshell.api.run("type.map_type_representations", self.file, related_object=element, relating_type=type)
assert len([e for e in self.file]) == total_elements
@@ -36,5 +36,5 @@ class TestGetBrickTypeIFC2X3(test.bootstrap.IFC2X3):
def test_run(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowController")
type_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcAirTerminalBoxType")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=type_element)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=type_element)
assert subject.get_brick_type(element) == "https://brickschema.org/schema/Brick#TerminalUnit"
@@ -69,7 +69,7 @@ class TestGetReferences(test.bootstrap.IFC4):
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
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)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
ifcopenshell.api.run("classification.add_classification", self.file, classification=classification)
ifcopenshell.api.run(
"classification.add_reference",
@@ -98,7 +98,7 @@ class TestGetReferences(test.bootstrap.IFC4):
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
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)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
ifcopenshell.api.run("classification.add_classification", self.file, classification=classification)
ifcopenshell.api.run(
"classification.add_reference",
@@ -55,7 +55,7 @@ class TestGetPsetIFC4(test.bootstrap.IFC4):
def test_getting_inherited_psets(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
type_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=type_element)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=type_element)
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=type_element, name="name")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": 1, "x": 1})
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="name")
@@ -79,7 +79,7 @@ class TestGetPsetIFC4(test.bootstrap.IFC4):
def test_excluding_inherited_psets(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
type_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=type_element)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=type_element)
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=type_element, name="name")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": 1, "x": 1})
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="name")
@@ -133,7 +133,7 @@ class TestGetPsetsIFC4(test.bootstrap.IFC4):
def test_getting_inherited_psets(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
type_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=type_element)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=type_element)
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=type_element, name="name")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": 1, "x": 1})
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="name")
@@ -263,14 +263,14 @@ class TestGetPredefinedTypeIFC4(test.bootstrap.IFC4):
def test_getting_an_inherited_predefined_type(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)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
element_type.PredefinedType = "PARTITIONING"
assert subject.get_predefined_type(element) == "PARTITIONING"
def test_getting_an_inherited_userdefined_type_for_an_element_type(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)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
element_type.PredefinedType = "USERDEFINED"
element_type.ElementType = "FOOBAR"
assert subject.get_predefined_type(element) == "FOOBAR"
@@ -278,7 +278,7 @@ class TestGetPredefinedTypeIFC4(test.bootstrap.IFC4):
def test_getting_an_overriden_predefined_type(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)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
element_type.PredefinedType = "NOTDEFINED"
element.PredefinedType = "PARTITIONING"
assert subject.get_predefined_type(element) == "PARTITIONING"
@@ -286,7 +286,7 @@ class TestGetPredefinedTypeIFC4(test.bootstrap.IFC4):
def test_getting_an_inherited_userdefined_type_for_a_process_type(self):
element = ifcopenshell.api.run("sequence.add_task", self.file)
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcTaskType")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
element_type.PredefinedType = "USERDEFINED"
element_type.ProcessType = "FOOBAR"
assert subject.get_predefined_type(element) == "FOOBAR"
@@ -296,7 +296,7 @@ class TestGetTypeIFC4(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)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
assert subject.get_type(element) == element_type
assert subject.get_type(element_type) == element_type
@@ -309,7 +309,7 @@ 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)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
assert subject.get_types(element_type) == (element,)
@@ -391,7 +391,7 @@ class TestGetMaterial(test.bootstrap.IFC4):
def test_getting_an_inherited_material_from_the_elements_type(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)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
material = ifcopenshell.api.run("material.add_material", self.file)
ifcopenshell.api.run("material.assign_material", self.file, product=element_type, material=material)
assert subject.get_material(element) == material
@@ -399,7 +399,7 @@ class TestGetMaterial(test.bootstrap.IFC4):
def test_getting_an_overridden_material_from_the_elements_occurrence(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)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
material = ifcopenshell.api.run("material.add_material", self.file)
ifcopenshell.api.run("material.assign_material", self.file, product=element_type, material=material)
material = ifcopenshell.api.run("material.add_material", self.file)
@@ -409,7 +409,7 @@ class TestGetMaterial(test.bootstrap.IFC4):
def test_getting_direct_materials_without_checking_inheritance(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)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
material = ifcopenshell.api.run("material.add_material", self.file)
ifcopenshell.api.run("material.assign_material", self.file, product=element_type, material=material)
assert subject.get_material(element, should_inherit=False) is None
@@ -493,7 +493,7 @@ class TestGetElementsByMaterial(test.bootstrap.IFC4):
def test_getting_elements_of_a_material_layer_set(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)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
material = ifcopenshell.api.run("material.add_material", self.file)
material_set = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialLayerSet")
ifcopenshell.api.run("material.add_layer", self.file, layer_set=material_set, material=material)
@@ -507,7 +507,7 @@ class TestGetElementsByMaterial(test.bootstrap.IFC4):
def test_getting_elements_of_a_material_profile_set(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)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
material = ifcopenshell.api.run("material.add_material", self.file)
material_set = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialProfileSet")
ifcopenshell.api.run("material.add_profile", self.file, profile_set=material_set, material=material)
@@ -168,7 +168,7 @@ class TestFilterElements(test.bootstrap.IFC4):
def test_selecting_by_type(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)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
assert subject.filter_elements(self.file, "IfcWall, type=Foo") == set()
element_type.Name = "Foo"
assert subject.filter_elements(self.file, "IfcWall, type=Foo") == {element}
@@ -465,10 +465,10 @@ class TestSelector(test.bootstrap.IFC4):
def test_getting_occurrences_of_a_filtered_type(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)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element_type2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", self.file, related_object=element2, relating_type=element_type2)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element2], relating_type=element_type2)
assert set(subject.Selector.parse(self.file, "* .IfcWallType")) == {element, element2}
def test_getting_decomposition_of_a_filtered_type(self):
@@ -505,7 +505,7 @@ class TestSelector(test.bootstrap.IFC4):
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")
element_type.Name = "Foo"
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=element_type)
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
assert set(subject.Selector.parse(self.file, '.IfcWall[type.Name="Foo"]')) == {element}
def test_selecting_via_a_material(self):