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
@@ -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):