Replace all ifcopenshell.api.run with ifcopenshell.api static functions.

This commit is contained in:
Dion Moult
2024-06-28 12:36:31 +10:00
parent b5d613989e
commit 07060fc769
432 changed files with 4633 additions and 4856 deletions
@@ -18,38 +18,47 @@
import numpy
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.unit
import ifcopenshell.api.type
import ifcopenshell.api.root
import ifcopenshell.api.void
import ifcopenshell.api.pset
import ifcopenshell.api.group
import ifcopenshell.api.system
import ifcopenshell.api.spatial
import ifcopenshell.api.geometry
import ifcopenshell.api.aggregate
import ifcopenshell.util
import ifcopenshell.util.system
class TestCopyClass(test.bootstrap.IFC4):
def test_copying_a_simple_element(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
new = ifcopenshell.api.root.copy_class(self.file, product=element)
assert new != element
assert new.GlobalId != element.GlobalId
assert new.is_a("IfcWall")
def test_copying_object_placements_so_children_of_the_original_element_dont_reference_the_new_element(self):
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
ifcopenshell.api.run("unit.assign_unit", self.file)
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
ifcopenshell.api.unit.assign_unit(self.file)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuilding")
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.spatial.assign_container(self.file, products=[subelement], relating_structure=element)
matrix = numpy.identity(4)
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=element, matrix=matrix.copy())
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=subelement, matrix=matrix.copy())
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
ifcopenshell.api.geometry.edit_object_placement(self.file, product=element, matrix=matrix.copy())
ifcopenshell.api.geometry.edit_object_placement(self.file, product=subelement, matrix=matrix.copy())
new = ifcopenshell.api.root.copy_class(self.file, product=element)
assert subelement.ObjectPlacement.PlacementRelTo == element.ObjectPlacement
assert subelement.ObjectPlacement.PlacementRelTo != new.ObjectPlacement
assert element.ObjectPlacement.RelativePlacement != new.ObjectPlacement.RelativePlacement
def test_copying_psets_so_changing_properties_of_the_new_element_does_not_affect_the_old(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foobar")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"foo": "bar"})
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Foobar")
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"foo": "bar"})
new = ifcopenshell.api.root.copy_class(self.file, product=element)
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
new_pset = new.IsDefinedBy[0].RelatingPropertyDefinition
assert element.IsDefinedBy[0] != new.IsDefinedBy[0]
@@ -60,10 +69,10 @@ class TestCopyClass(test.bootstrap.IFC4):
assert pset.HasProperties[0].NominalValue.wrappedValue == new_pset.HasProperties[0].NominalValue.wrappedValue
def test_copying_type_psets_so_changing_properties_of_the_new_type_does_not_affect_the_old(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foobar")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"foo": "bar"})
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Foobar")
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"foo": "bar"})
new = ifcopenshell.api.root.copy_class(self.file, product=element)
pset = element.HasPropertySets[0]
new_pset = new.HasPropertySets[0]
assert element.HasPropertySets[0] != new.HasPropertySets[0]
@@ -74,128 +83,128 @@ class TestCopyClass(test.bootstrap.IFC4):
assert pset.HasProperties[0].NominalValue.wrappedValue == new_pset.HasProperties[0].NominalValue.wrappedValue
def test_copying_a_container_only_and_not_its_contents(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuilding")
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.spatial.assign_container(self.file, products=[subelement], relating_structure=element)
new = ifcopenshell.api.root.copy_class(self.file, product=element)
assert element.ContainsElements
assert not new.ContainsElements
def test_copying_contents_of_a_container_and_maintaining_the_containment_relationship(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
new = ifcopenshell.api.run("root.copy_class", self.file, product=subelement)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuilding")
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.spatial.assign_container(self.file, products=[subelement], relating_structure=element)
new = ifcopenshell.api.root.copy_class(self.file, product=subelement)
assert new.ContainedInStructure[0].RelatingStructure == element
def test_copying_a_container_only_and_not_its_decomposition(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuildingStorey")
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuilding")
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuildingStorey")
ifcopenshell.api.aggregate.assign_object(self.file, products=[subelement], relating_object=element)
new = ifcopenshell.api.root.copy_class(self.file, product=element)
assert element.IsDecomposedBy
assert not new.IsDecomposedBy
def test_copying_an_aggregate_only_and_not_its_decomposition(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcElementAssembly")
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBeam")
ifcopenshell.api.aggregate.assign_object(self.file, products=[subelement], relating_object=element)
new = ifcopenshell.api.root.copy_class(self.file, product=element)
assert element.IsDecomposedBy
assert not new.IsDecomposedBy
def test_copying_an_aggregate_decomposition_and_maintaining_the_aggregate_relationship(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
new = ifcopenshell.api.run("root.copy_class", self.file, product=subelement)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcElementAssembly")
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBeam")
ifcopenshell.api.aggregate.assign_object(self.file, products=[subelement], relating_object=element)
new = ifcopenshell.api.root.copy_class(self.file, product=subelement)
assert new.Decomposes[0].RelatingObject == element
def test_not_copying_any_representations_because_life_is_hard(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
element.Representation = self.file.createIfcProductDefinitionShape()
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
new = ifcopenshell.api.root.copy_class(self.file, product=element)
assert new.Representation is None
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
element.RepresentationMaps = [self.file.createIfcRepresentationMap()]
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
new = ifcopenshell.api.root.copy_class(self.file, product=element)
assert new.RepresentationMaps is None
def test_copying_an_element_with_an_opening(self):
# IfcOpeningElement opening
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement")
ifcopenshell.api.run("void.add_opening", self.file, opening=opening, element=wall)
new = ifcopenshell.api.run("root.copy_class", self.file, product=wall)
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
opening = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcOpeningElement")
ifcopenshell.api.void.add_opening(self.file, opening=opening, element=wall)
new = ifcopenshell.api.root.copy_class(self.file, product=wall)
assert wall.HasOpenings[0] != new.HasOpenings[0]
assert wall.HasOpenings[0].RelatedOpeningElement == opening
assert new.HasOpenings[0].RelatedOpeningElement != opening
assert new.HasOpenings[0].RelatedOpeningElement.is_a("IfcOpeningElement")
# IfcVoidingFeature opening
plate = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcPlate")
opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcVoidingFeature")
ifcopenshell.api.run("void.add_opening", self.file, opening=opening, element=plate)
new = ifcopenshell.api.run("root.copy_class", self.file, product=plate)
plate = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcPlate")
opening = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcVoidingFeature")
ifcopenshell.api.void.add_opening(self.file, opening=opening, element=plate)
new = ifcopenshell.api.root.copy_class(self.file, product=plate)
assert plate.HasOpenings[0] != new.HasOpenings[0]
assert plate.HasOpenings[0].RelatedOpeningElement == opening
assert new.HasOpenings[0].RelatedOpeningElement != opening
assert new.HasOpenings[0].RelatedOpeningElement.is_a("IfcVoidingFeature")
def test_copying_an_element_with_a_filled_opening_should_not_copy_the_opening_nor_fill(self):
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement")
window = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWindow")
ifcopenshell.api.run("void.add_opening", self.file, opening=opening, element=wall)
ifcopenshell.api.run("void.add_filling", self.file, opening=opening, element=window)
new = ifcopenshell.api.run("root.copy_class", self.file, product=wall)
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
opening = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcOpeningElement")
window = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWindow")
ifcopenshell.api.void.add_opening(self.file, opening=opening, element=wall)
ifcopenshell.api.void.add_filling(self.file, opening=opening, element=window)
new = ifcopenshell.api.root.copy_class(self.file, product=wall)
assert not new.HasOpenings
def test_copying_an_opening_voiding_an_element(self):
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement")
ifcopenshell.api.run("void.add_opening", self.file, opening=opening, element=wall)
new = ifcopenshell.api.run("root.copy_class", self.file, product=opening)
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
opening = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcOpeningElement")
ifcopenshell.api.void.add_opening(self.file, opening=opening, element=wall)
new = ifcopenshell.api.root.copy_class(self.file, product=opening)
assert opening.VoidsElements[0] != new.VoidsElements[0]
assert new.VoidsElements[0].RelatingBuildingElement == wall
def test_copying_an_opening_with_a_filling(self):
door = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDoor")
opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement")
ifcopenshell.api.run("void.add_filling", self.file, opening=opening, element=door)
new = ifcopenshell.api.run("root.copy_class", self.file, product=opening)
door = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcDoor")
opening = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcOpeningElement")
ifcopenshell.api.void.add_filling(self.file, opening=opening, element=door)
new = ifcopenshell.api.root.copy_class(self.file, product=opening)
assert not new.HasFillings
def test_copying_a_filling(self):
door = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDoor")
opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement")
ifcopenshell.api.run("void.add_filling", self.file, opening=opening, element=door)
new = ifcopenshell.api.run("root.copy_class", self.file, product=door)
door = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcDoor")
opening = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcOpeningElement")
ifcopenshell.api.void.add_filling(self.file, opening=opening, element=door)
new = ifcopenshell.api.root.copy_class(self.file, product=door)
assert not new.FillsVoids
def test_retaining_a_single_material(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
material = self.file.createIfcMaterial()
self.file.createIfcRelAssociatesMaterial(RelatedObjects=[element], RelatingMaterial=material)
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
new = ifcopenshell.api.root.copy_class(self.file, product=element)
assert new.HasAssociations[0].RelatingMaterial == element.HasAssociations[0].RelatingMaterial
assert new.HasAssociations[0].RelatingMaterial.is_a("IfcMaterial")
def test_copying_material_set_usages(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
material = self.file.createIfcMaterialLayerSetUsage()
self.file.createIfcRelAssociatesMaterial(RelatedObjects=[element], RelatingMaterial=material)
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
new = ifcopenshell.api.root.copy_class(self.file, product=element)
assert new.HasAssociations[0].RelatingMaterial != element.HasAssociations[0].RelatingMaterial
assert new.HasAssociations[0].RelatingMaterial.is_a("IfcMaterialLayerSetUsage")
def test_copying_material_sets_for_type_elements_only(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
single_material = self.file.createIfcMaterial()
layer = self.file.createIfcMaterialLayer(Material=single_material)
material = self.file.createIfcMaterialLayerSet(MaterialLayers=[layer])
self.file.createIfcRelAssociatesMaterial(RelatedObjects=[element], RelatingMaterial=material)
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
new = ifcopenshell.api.root.copy_class(self.file, product=element)
assert new.HasAssociations[0].RelatingMaterial.is_a("IfcMaterialLayerSet")
assert new.HasAssociations[0].RelatingMaterial != element.HasAssociations[0].RelatingMaterial
assert (
@@ -208,25 +217,25 @@ 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_objects=[element], relating_type=type)
new = ifcopenshell.api.run("root.copy_class", self.file, product=type)
type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=type)
new = ifcopenshell.api.root.copy_class(self.file, product=type)
assert not new.Types
def test_copying_distribution_ports(self):
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
ifcopenshell.api.run("unit.assign_unit", self.file)
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcChiller")
port = ifcopenshell.api.run("system.add_port", self.file)
ifcopenshell.api.run("system.assign_port", self.file, element=element, port=port)
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
ifcopenshell.api.unit.assign_unit(self.file)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcChiller")
port = ifcopenshell.api.system.add_port(self.file)
ifcopenshell.api.system.assign_port(self.file, element=element, port=port)
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcChiller")
port2 = ifcopenshell.api.run("system.add_port", self.file)
ifcopenshell.api.run("system.assign_port", self.file, element=element2, port=port2)
ifcopenshell.api.run("system.connect_port", self.file, port1=port, port2=port2, direction="NOTDEFINED")
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcChiller")
port2 = ifcopenshell.api.system.add_port(self.file)
ifcopenshell.api.system.assign_port(self.file, element=element2, port=port2)
ifcopenshell.api.system.connect_port(self.file, port1=port, port2=port2, direction="NOTDEFINED")
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
new = ifcopenshell.api.root.copy_class(self.file, product=element)
new_ports = ifcopenshell.util.system.get_ports(new)
assert port not in new_ports
assert new_ports[0].is_a("IfcDistributionPort")
@@ -235,17 +244,16 @@ class TestCopyClass(test.bootstrap.IFC4):
assert not ifcopenshell.util.system.get_connected_port(new_ports[0])
def test_not_copying_path_connections(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")
ifcopenshell.api.run(
"geometry.connect_path",
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.geometry.connect_path(
self.file,
relating_element=element1,
related_element=element2,
relating_connection="ATSTART",
related_connection="ATEND",
)
new = ifcopenshell.api.run("root.copy_class", self.file, product=element1)
new = ifcopenshell.api.root.copy_class(self.file, product=element1)
assert len(self.file.by_type("IfcRelConnectsPathElements")) == 1
assert element1.ConnectedTo
assert element2.ConnectedFrom
@@ -253,20 +261,20 @@ class TestCopyClass(test.bootstrap.IFC4):
assert not new.ConnectedFrom
def test_maintaining_group_relationships(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
group = ifcopenshell.api.run("group.add_group", self.file)
ifcopenshell.api.run("group.assign_group", self.file, group=group, products=[element])
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
group = ifcopenshell.api.group.add_group(self.file)
ifcopenshell.api.group.assign_group(self.file, group=group, products=[element])
new = ifcopenshell.api.root.copy_class(self.file, product=element)
assert len(self.file.by_type("IfcRelAssignsToGroup")) == 1
assert new.HasAssignments[0].RelatingGroup == group
class TestCopyClassIFC2X3(test.bootstrap.IFC2X3):
def test_copying_distribution_ports(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowTerminal")
port = ifcopenshell.api.run("system.add_port", self.file)
ifcopenshell.api.run("system.assign_port", self.file, element=element, port=port)
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcFlowTerminal")
port = ifcopenshell.api.system.add_port(self.file)
ifcopenshell.api.system.assign_port(self.file, element=element, port=port)
new = ifcopenshell.api.root.copy_class(self.file, product=element)
new_ports = ifcopenshell.util.system.get_ports(new)
assert port not in new_ports
assert new_ports[0].is_a("IfcDistributionPort")
@@ -17,13 +17,13 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.root
class TestCreateEntity(test.bootstrap.IFC4):
def test_creating_a_simple_entity_with_automatic_global_id(self):
wall = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcRailing", predefined_type="HANDRAIL", name="Foo"
wall = ifcopenshell.api.root.create_entity(
self.file, ifc_class="IfcRailing", predefined_type="HANDRAIL", name="Foo"
)
assert wall.is_a() == "IfcRailing"
assert len(wall.GlobalId) == 22
@@ -31,48 +31,48 @@ class TestCreateEntity(test.bootstrap.IFC4):
assert wall.PredefinedType == "HANDRAIL"
def test_handling_predefined_types(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcRailing", name="Foo")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcRailing", name="Foo")
assert element.PredefinedType is None
element = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcRailing", predefined_type="HANDRAIL", name="Foo"
element = ifcopenshell.api.root.create_entity(
self.file, ifc_class="IfcRailing", predefined_type="HANDRAIL", name="Foo"
)
assert element.PredefinedType == "HANDRAIL"
element = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcRailing", predefined_type="Foobar", name="Foo"
element = ifcopenshell.api.root.create_entity(
self.file, ifc_class="IfcRailing", predefined_type="Foobar", name="Foo"
)
assert element.PredefinedType == "USERDEFINED"
assert element.ObjectType == "Foobar"
element = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcWallType", predefined_type="Foobar", name="Foo"
element = ifcopenshell.api.root.create_entity(
self.file, ifc_class="IfcWallType", predefined_type="Foobar", name="Foo"
)
assert element.PredefinedType == "USERDEFINED"
assert element.ElementType == "Foobar"
if self.file.schema != "IFC2X3":
element = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcTaskType", predefined_type="Foobar", name="Foo"
element = ifcopenshell.api.root.create_entity(
self.file, ifc_class="IfcTaskType", predefined_type="Foobar", name="Foo"
)
assert element.PredefinedType == "USERDEFINED"
assert element.ProcessType == "Foobar"
def test_setting_default_values_for_validity(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType", name="Foo")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType", name="Foo")
assert element.PredefinedType == "NOTDEFINED"
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDoorStyle", name="Foo")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcDoorStyle", name="Foo")
assert element.OperationType == "NOTDEFINED"
assert element.ConstructionType == "NOTDEFINED"
assert element.ParameterTakesPrecedence == False
assert element.Sizeable == False
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWindowStyle", name="Foo")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWindowStyle", name="Foo")
assert element.OperationType == "NOTDEFINED"
assert element.ConstructionType == "NOTDEFINED"
assert element.ParameterTakesPrecedence == False
assert element.Sizeable == False
if self.file.schema != "IFC2X3":
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDoorType", name="Foo")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcDoorType", name="Foo")
assert element.OperationType == "NOTDEFINED"
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWindowType", name="Foo")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWindowType", name="Foo")
assert element.PartitioningType == "NOTDEFINED"
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFurnitureType", name="Foo")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcFurnitureType", name="Foo")
assert element.AssemblyPlace == "NOTDEFINED"
@@ -17,52 +17,53 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.type
import ifcopenshell.api.root
import ifcopenshell.util.element
class TestReassignClass(test.bootstrap.IFC4):
def test_reassigning_a_simple_class(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
n_elements = len([e for e in self.file])
original_id = element.id()
new = ifcopenshell.api.run("root.reassign_class", self.file, product=element, ifc_class="IfcSlab")
new = ifcopenshell.api.root.reassign_class(self.file, product=element, ifc_class="IfcSlab")
assert len([e for e in self.file]) == n_elements
assert new.id() == original_id
assert new.is_a("IfcSlab")
def test_reassigning_a_predefined_type(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
new = ifcopenshell.api.run(
"root.reassign_class", self.file, product=element, ifc_class="IfcSlab", predefined_type="FLOOR"
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
new = ifcopenshell.api.root.reassign_class(
self.file, product=element, ifc_class="IfcSlab", predefined_type="FLOOR"
)
assert new.PredefinedType == "FLOOR"
def test_falling_back_to_userdefined_if_the_predefined_type_cannot_be_reassigned_for_occurrence_class(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
new = ifcopenshell.api.run(
"root.reassign_class", self.file, product=element, ifc_class="IfcSlab", predefined_type="FOO"
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
new = ifcopenshell.api.root.reassign_class(
self.file, product=element, ifc_class="IfcSlab", predefined_type="FOO"
)
assert new.PredefinedType == "USERDEFINED"
assert new.ObjectType == "FOO"
def test_falling_back_to_userdefined_if_the_predefined_type_cannot_be_reassigned_for_type_class(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
new = ifcopenshell.api.run(
"root.reassign_class", self.file, product=element, ifc_class="IfcSlabType", predefined_type="FOO"
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
new = ifcopenshell.api.root.reassign_class(
self.file, product=element, ifc_class="IfcSlabType", predefined_type="FOO"
)
assert new.PredefinedType == "USERDEFINED"
assert new.ElementType == "FOO"
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_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_objects=[element2], relating_type=element_type)
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1], relating_type=element_type)
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.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"
element_type = ifcopenshell.api.root.reassign_class(
self.file, product=element_type, ifc_class="IfcSlabType"
)
# type occurrences have reassigned classes
@@ -75,13 +76,13 @@ class TestReassignClass(test.bootstrap.IFC4):
assert len(self.file.by_type("IfcWallType")) == 0
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_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_objects=[element2], relating_type=element_type)
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1], relating_type=element_type)
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.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")
element1 = ifcopenshell.api.root.reassign_class(self.file, product=element1, ifc_class="IfcSlab")
# occurrence type has reassigned class
element_type = ifcopenshell.util.element.get_type(element1)
@@ -17,68 +17,83 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.unit
import ifcopenshell.api.nest
import ifcopenshell.api.root
import ifcopenshell.api.void
import ifcopenshell.api.grid
import ifcopenshell.api.type
import ifcopenshell.api.pset
import ifcopenshell.api.group
import ifcopenshell.api.owner
import ifcopenshell.api.system
import ifcopenshell.api.spatial
import ifcopenshell.api.drawing
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.api.material
import ifcopenshell.api.aggregate
import ifcopenshell.guid
class TestRemoveProduct(test.bootstrap.IFC4):
def test_removing_an_element_by_itself(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("root.remove_product", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.root.remove_product(self.file, product=element)
assert len(self.file.by_type("IfcWall")) == 0
def test_removing_an_element_local_placement(self):
# just removing the product with the placement
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
placement = ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=element)
ifcopenshell.api.run("root.remove_product", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
placement = ifcopenshell.api.geometry.edit_object_placement(self.file, product=element)
ifcopenshell.api.root.remove_product(self.file, product=element)
assert len(self.file.by_type("IfcObjectPlacement")) == 0
# removing the product that shares the placement with other product
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
placement = ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=element)
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
placement = ifcopenshell.api.geometry.edit_object_placement(self.file, product=element)
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
element1.ObjectPlacement = placement
ifcopenshell.api.run("root.remove_product", self.file, product=element)
ifcopenshell.api.root.remove_product(self.file, product=element)
assert len(self.file.by_type("IfcObjectPlacement")) == 1
ifcopenshell.api.run("root.remove_product", self.file, product=element1)
ifcopenshell.api.root.remove_product(self.file, product=element1)
assert len(self.file.by_type("IfcObjectPlacement")) == 0
# removing the product that's placement used as a reference point for another placement
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
placement = ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=element)
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
placement1 = ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=element1)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
placement = ifcopenshell.api.geometry.edit_object_placement(self.file, product=element)
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
placement1 = ifcopenshell.api.geometry.edit_object_placement(self.file, product=element1)
placement.PlacementRelTo = placement1
ifcopenshell.api.run("root.remove_product", self.file, product=element)
ifcopenshell.api.root.remove_product(self.file, product=element)
assert len(self.file.by_type("IfcObjectPlacement")) == 1
ifcopenshell.api.run("root.remove_product", self.file, product=element1)
ifcopenshell.api.root.remove_product(self.file, product=element1)
assert len(self.file.by_type("IfcObjectPlacement")) == 0
def test_removing_element_type_psets(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": "Bar"})
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Foo_Bar")
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Foo": "Bar"})
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
element2.HasPropertySets = (pset,)
# make sure it won't remove the pset if it's connected elsewhere
ifcopenshell.api.run("root.remove_product", self.file, product=element2)
ifcopenshell.api.root.remove_product(self.file, product=element2)
assert len(self.file.by_type("IfcPropertySet")) == 1
assert len(self.file.by_type("IfcPropertySingleValue")) == 1
# if it's the product is the only inverse for pset, it should remove the pset
ifcopenshell.api.run("root.remove_product", self.file, product=element)
ifcopenshell.api.root.remove_product(self.file, product=element)
assert len(self.file.by_type("IfcPropertySet")) == 0
assert len(self.file.by_type("IfcPropertySingleValue")) == 0
def test_removing_all_representations_of_an_element(self):
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
ifcopenshell.api.run("unit.assign_unit", self.file)
context = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
ifcopenshell.api.unit.assign_unit(self.file)
context = ifcopenshell.api.context.add_context(self.file, context_type="Model")
total_entities = len(list(self.file))
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
element.Representation = self.file.createIfcProductDefinitionShape(
Representations=[
self.file.createIfcShapeRepresentation(
@@ -86,7 +101,7 @@ class TestRemoveProduct(test.bootstrap.IFC4):
)
]
)
ifcopenshell.api.run("root.remove_product", self.file, product=element)
ifcopenshell.api.root.remove_product(self.file, product=element)
assert len(list(self.file)) == total_entities
assert len(self.file.by_type("IfcProductDefinitionShape")) == 0
assert len(self.file.by_type("IfcShapeRepresentation")) == 0
@@ -94,10 +109,10 @@ class TestRemoveProduct(test.bootstrap.IFC4):
assert len(self.file.by_type("IfcWall")) == 0
def test_unassigning_but_not_removing_mapped_representations_of_an_element(self):
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
ifcopenshell.api.run("unit.assign_unit", self.file)
context = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
ifcopenshell.api.unit.assign_unit(self.file)
context = ifcopenshell.api.context.add_context(self.file, context_type="Model")
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
rep_map = self.file.createIfcRepresentationMap(
MappingOrigin=self.file.createIfcAxis2Placement3D(),
MappedRepresentation=self.file.createIfcShapeRepresentation(
@@ -106,10 +121,9 @@ class TestRemoveProduct(test.bootstrap.IFC4):
)
element_type.RepresentationMaps = [rep_map]
total_entities = len(list(self.file))
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
# should_map_representations=False to create mapping manually
ifcopenshell.api.run(
"type.assign_type",
ifcopenshell.api.type.assign_type(
self.file,
related_objects=[element],
relating_type=element_type,
@@ -129,7 +143,7 @@ class TestRemoveProduct(test.bootstrap.IFC4):
]
)
assert len(self.file.by_type("IfcShapeRepresentation")) == 2
ifcopenshell.api.run("root.remove_product", self.file, product=element)
ifcopenshell.api.root.remove_product(self.file, product=element)
assert len(list(self.file)) == total_entities
assert len(self.file.by_type("IfcProductDefinitionShape")) == 0
assert len(self.file.by_type("IfcShapeRepresentation")) == 1
@@ -138,329 +152,316 @@ class TestRemoveProduct(test.bootstrap.IFC4):
assert len(self.file.by_type("IfcWall")) == 0
def test_removing_an_element_type_by_itself(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
ifcopenshell.api.run("root.remove_product", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
ifcopenshell.api.root.remove_product(self.file, product=element)
assert len(self.file.by_type("IfcWallType")) == 0
def test_removing_all_openings_of_an_element(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement")
ifcopenshell.api.run("void.add_opening", self.file, opening=opening, element=element)
ifcopenshell.api.run("root.remove_product", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
opening = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcOpeningElement")
ifcopenshell.api.void.add_opening(self.file, opening=opening, element=element)
ifcopenshell.api.root.remove_product(self.file, product=element)
assert len(list(self.file)) == 0
assert len(self.file.by_type("IfcWall")) == 0
assert len(self.file.by_type("IfcOpeningElement")) == 0
assert len(self.file.by_type("IfcRelVoidsElement")) == 0
def test_removing_axes_of_a_grid(self):
grid = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcGrid")
axis = ifcopenshell.api.run("grid.create_grid_axis", self.file, uvw_axes="UAxes", grid=grid)
grid = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcGrid")
axis = ifcopenshell.api.grid.create_grid_axis(self.file, uvw_axes="UAxes", grid=grid)
axis.AxisCurve = self.file.createIfcPolyline()
axis = ifcopenshell.api.run("grid.create_grid_axis", self.file, uvw_axes="VAxes", grid=grid)
axis = ifcopenshell.api.grid.create_grid_axis(self.file, uvw_axes="VAxes", grid=grid)
axis.AxisCurve = self.file.createIfcPolyline()
total_entities = len(list(self.file))
ifcopenshell.api.run("root.remove_product", self.file, product=grid)
ifcopenshell.api.root.remove_product(self.file, product=grid)
assert len(list(self.file)) == 0
def test_removing_all_void_relationships_of_an_opening(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
total_entities = len(list(self.file))
opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement")
ifcopenshell.api.run("void.add_opening", self.file, opening=opening, element=element)
ifcopenshell.api.run("root.remove_product", self.file, product=opening)
opening = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcOpeningElement")
ifcopenshell.api.void.add_opening(self.file, opening=opening, element=element)
ifcopenshell.api.root.remove_product(self.file, product=opening)
assert len(list(self.file)) == total_entities
assert len(self.file.by_type("IfcOpeningElement")) == 0
assert len(self.file.by_type("IfcRelVoidsElement")) == 0
def test_removing_all_fill_relationships_of_a_filling(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement")
filling = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDoor")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
opening = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcOpeningElement")
filling = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcDoor")
total_entities = len(list(self.file))
ifcopenshell.api.run("void.add_opening", self.file, opening=opening, element=element)
ifcopenshell.api.run("void.add_filling", self.file, opening=opening, element=filling)
ifcopenshell.api.run("root.remove_product", self.file, product=filling)
ifcopenshell.api.void.add_opening(self.file, opening=opening, element=element)
ifcopenshell.api.void.add_filling(self.file, opening=opening, element=filling)
ifcopenshell.api.root.remove_product(self.file, product=filling)
assert len(list(self.file)) == total_entities
assert len(self.file.by_type("IfcDoor")) == 0
assert len(self.file.by_type("IfcRelFillsElement")) == 0
def test_removing_all_distribution_ports(self):
total_entities = len(list(self.file))
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
port = ifcopenshell.api.run("system.add_port", self.file, element=element)
ifcopenshell.api.run("root.remove_product", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcFlowSegment")
port = ifcopenshell.api.system.add_port(self.file, element=element)
ifcopenshell.api.root.remove_product(self.file, product=element)
assert len(list(self.file)) == total_entities
assert len(self.file.by_type("IfcFlowSegment")) == 0
assert len(self.file.by_type("IfcRelNests")) == 0
assert len(self.file.by_type("IfcDistributionPort")) == 0
def test_removing_all_nesting_relationships_of_a_whole(self):
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBeam")
total_entities = len(list(self.file))
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("nest.assign_object", self.file, related_objects=[subelement], relating_object=element)
ifcopenshell.api.run("root.remove_product", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.nest.assign_object(self.file, related_objects=[subelement], relating_object=element)
ifcopenshell.api.root.remove_product(self.file, product=element)
assert len(list(self.file)) == total_entities
assert len(self.file.by_type("IfcRelNests")) == 0
assert len(self.file.by_type("IfcWall")) == 0
assert len(self.file.by_type("IfcBeam")) == 1
def test_removing_all_nesting_relationships_of_a_part(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
total_entities = len(list(self.file))
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
ifcopenshell.api.run("nest.assign_object", self.file, related_objects=[subelement], relating_object=element)
ifcopenshell.api.run("root.remove_product", self.file, product=subelement)
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBeam")
ifcopenshell.api.nest.assign_object(self.file, related_objects=[subelement], relating_object=element)
ifcopenshell.api.root.remove_product(self.file, product=subelement)
assert len(list(self.file)) == total_entities
assert len(self.file.by_type("IfcRelNests")) == 0
assert len(self.file.by_type("IfcWall")) == 1
assert len(self.file.by_type("IfcBeam")) == 0
def test_removing_all_aggregate_relationships_of_a_whole(self):
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBeam")
total_entities = len(list(self.file))
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
ifcopenshell.api.run("root.remove_product", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcElementAssembly")
ifcopenshell.api.aggregate.assign_object(self.file, products=[subelement], relating_object=element)
ifcopenshell.api.root.remove_product(self.file, product=element)
assert len(list(self.file)) == total_entities
assert len(self.file.by_type("IfcRelAggregates")) == 0
assert len(self.file.by_type("IfcElementAssembly")) == 0
assert len(self.file.by_type("IfcBeam")) == 1
def test_removing_all_aggregate_relationships_of_a_part(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcElementAssembly")
total_entities = len(list(self.file))
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
ifcopenshell.api.run("root.remove_product", self.file, product=subelement)
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBeam")
ifcopenshell.api.aggregate.assign_object(self.file, products=[subelement], relating_object=element)
ifcopenshell.api.root.remove_product(self.file, product=subelement)
assert len(list(self.file)) == total_entities
assert len(self.file.by_type("IfcRelAggregates")) == 0
assert len(self.file.by_type("IfcElementAssembly")) == 1
assert len(self.file.by_type("IfcBeam")) == 0
def test_removing_all_containment_relationships_of_a_container(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSpace")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSpace")
total_entities = len(list(self.file))
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
ifcopenshell.api.run("root.remove_product", self.file, product=element)
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.spatial.assign_container(self.file, products=[subelement], relating_structure=element)
ifcopenshell.api.root.remove_product(self.file, product=element)
assert len(list(self.file)) == total_entities
assert len(self.file.by_type("IfcRelContainedInSpatialStructure")) == 0
assert len(self.file.by_type("IfcSpace")) == 0
assert len(self.file.by_type("IfcWall")) == 1
def test_removing_all_containment_relationships_of_an_element(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSpace")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSpace")
total_entities = len(list(self.file))
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
ifcopenshell.api.run("root.remove_product", self.file, product=subelement)
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.spatial.assign_container(self.file, products=[subelement], relating_structure=element)
ifcopenshell.api.root.remove_product(self.file, product=subelement)
assert len(list(self.file)) == total_entities
assert len(self.file.by_type("IfcRelContainedInSpatialStructure")) == 0
assert len(self.file.by_type("IfcSpace")) == 1
assert len(self.file.by_type("IfcWall")) == 0
def test_removing_path_connection_relationships_of_an_element(self):
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcColumn")
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcColumn")
total_entities = len(list(self.file))
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
ifcopenshell.api.run("geometry.connect_path", self.file, relating_element=element1, related_element=element2)
ifcopenshell.api.run("root.remove_product", self.file, product=element1)
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBeam")
ifcopenshell.api.geometry.connect_path(self.file, relating_element=element1, related_element=element2)
ifcopenshell.api.root.remove_product(self.file, product=element1)
assert len(list(self.file)) == total_entities
assert len(self.file.by_type("IfcRelConnectsPathElements")) == 0
assert len(self.file.by_type("IfcColumn")) == 1
assert len(self.file.by_type("IfcBeam")) == 0
def test_removing_connection_relationships_of_an_element(self):
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSlab")
total_entities = len(list(self.file))
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run(
"geometry.connect_element",
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.geometry.connect_element(
self.file,
related_element=element1,
relating_element=element2,
)
ifcopenshell.api.run("root.remove_product", self.file, product=element1)
ifcopenshell.api.root.remove_product(self.file, product=element1)
assert len(list(self.file)) == total_entities
assert len(self.file.by_type("IfcRelConnectsElements")) == 0
assert len(self.file.by_type("IfcSlab")) == 1
assert len(self.file.by_type("IfcWall")) == 0
def test_removing_connection_relationships_of_an_element_with_additional_realizing_element(self):
slab1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
slab2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
slab1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSlab")
slab2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSlab")
total_entities = len(list(self.file))
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
self.file.createIfcRelConnectsWithRealizingElements(
ifcopenshell.guid.new(),
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", self.file),
OwnerHistory=ifcopenshell.api.owner.create_owner_history(self.file),
RelatingElement=wall,
RelatedElement=slab1,
RealizingElements=(wall, slab1, slab2),
)
ifcopenshell.api.run("root.remove_product", self.file, product=wall)
ifcopenshell.api.root.remove_product(self.file, product=wall)
assert len(list(self.file)) == total_entities
assert len(self.file.by_type("IfcRelConnectsElements")) == 0
assert len(self.file.by_type("IfcSlab")) == 2
assert len(self.file.by_type("IfcWall")) == 0
def test_removing_connection_relationships_of_an_element_element_is_realizing_element(self):
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
slab1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
slab1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSlab")
total_entities = len(list(self.file))
slab2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
slab2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSlab")
slab2_entities = len(list(self.file)) - total_entities
self.file.createIfcRelConnectsWithRealizingElements(
ifcopenshell.guid.new(),
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", self.file),
OwnerHistory=ifcopenshell.api.owner.create_owner_history(self.file),
RelatingElement=wall,
RelatedElement=slab1,
RealizingElements=(wall, slab1, slab2),
)
total_entities = len(list(self.file))
ifcopenshell.api.run("root.remove_product", self.file, product=slab2)
ifcopenshell.api.root.remove_product(self.file, product=slab2)
assert len(list(self.file)) == (total_entities - slab2_entities)
assert len(self.file.by_type("IfcRelConnectsElements")) == 1
assert len(self.file.by_type("IfcSlab")) == 1
assert len(self.file.by_type("IfcWall")) == 1
def test_removing_connection_relationships_of_an_element_element_is_only_realizing_element(self):
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
slab1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
slab1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSlab")
total_entities = len(list(self.file))
slab2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
slab2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSlab")
self.file.createIfcRelConnectsWithRealizingElements(
ifcopenshell.guid.new(),
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", self.file),
OwnerHistory=ifcopenshell.api.owner.create_owner_history(self.file),
RelatingElement=wall,
RelatedElement=slab1,
RealizingElements=(slab2,),
)
ifcopenshell.api.run("root.remove_product", self.file, product=slab2)
ifcopenshell.api.root.remove_product(self.file, product=slab2)
assert len(list(self.file)) == total_entities
assert len(self.file.by_type("IfcRelConnectsElements")) == 0
assert len(self.file.by_type("IfcSlab")) == 1
assert len(self.file.by_type("IfcWall")) == 1
def test_removing_ports_connection_relationship(self):
port1 = ifcopenshell.api.run("system.add_port", self.file)
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
ifcopenshell.api.run("system.assign_port", self.file, element=element1, port=port1)
port1 = ifcopenshell.api.system.add_port(self.file)
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcFlowSegment")
ifcopenshell.api.system.assign_port(self.file, element=element1, port=port1)
port2 = ifcopenshell.api.run("system.add_port", self.file)
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
ifcopenshell.api.run("system.assign_port", self.file, element=element2, port=port2)
port2 = ifcopenshell.api.system.add_port(self.file)
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcFlowSegment")
ifcopenshell.api.system.assign_port(self.file, element=element2, port=port2)
ifcopenshell.api.run("system.connect_port", self.file, port1=port1, port2=port2, direction="SOURCE")
ifcopenshell.api.system.connect_port(self.file, port1=port1, port2=port2, direction="SOURCE")
connection = self.file.by_type("IfcRelConnectsPorts")[0]
# making sure removing realizing element won't remove the entire connection since it's optional
element3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
element3 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcFlowSegment")
connection.RealizingElement = element3
ifcopenshell.api.run("root.remove_product", self.file, product=element3)
ifcopenshell.api.root.remove_product(self.file, product=element3)
assert len(self.file.by_type("IfcRelConnectsPorts")) == 1
ifcopenshell.api.run("root.remove_product", self.file, product=element1)
ifcopenshell.api.root.remove_product(self.file, product=element1)
assert len(self.file.by_type("IfcRelConnectsPorts")) == 0
assert len(self.file.by_type("IfcFlowSegment")) == 1
assert len(self.file.by_type("IfcDistributionPort")) == 1
def test_removing_all_property_relationships_of_an_element(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": "Bar"})
ifcopenshell.api.run("root.remove_product", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Foo_Bar")
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Foo": "Bar"})
ifcopenshell.api.root.remove_product(self.file, product=element)
assert not self.file.by_type("IfcRelDefinesByProperties")
assert not self.file.by_type("IfcPropertySet")
assert not self.file.by_type("IfcPropertySingleValue")
def test_removing_all_material_relationships_of_an_element(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
material = ifcopenshell.api.run("material.add_material", self.file, name="Foo")
ifcopenshell.api.run("material.assign_material", self.file, products=[element], material=material)
ifcopenshell.api.run("root.remove_product", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
material = ifcopenshell.api.material.add_material(self.file, name="Foo")
ifcopenshell.api.material.assign_material(self.file, products=[element], material=material)
ifcopenshell.api.root.remove_product(self.file, product=element)
assert not self.file.by_type("IfcRelAssociatesMaterial")
assert self.file.by_type("IfcMaterial")
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_objects=[element], relating_type=element_type)
ifcopenshell.api.run("root.remove_product", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
ifcopenshell.api.root.remove_product(self.file, product=element)
assert not self.file.by_type("IfcRelDefinesByType")
assert self.file.by_type("IfcWallType")
def test_removing_all_type_relationships_of_an_element_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")
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)
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1], relating_type=element_type)
ifcopenshell.api.type.assign_type(self.file, related_objects=[element2], relating_type=element_type)
ifcopenshell.api.root.remove_product(self.file, product=element_type)
assert not self.file.by_type("IfcRelDefinesByType")
assert self.file.by_type("IfcWall")
def test_removing_all_space_boundaries_of_an_element(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
boundary = self.file.createIfcRelSpaceBoundary(GlobalId=ifcopenshell.guid.new(), RelatedBuildingElement=element)
ifcopenshell.api.run("root.remove_product", self.file, product=element)
ifcopenshell.api.root.remove_product(self.file, product=element)
assert not self.file.by_type("IfcRelSpaceBoundary")
def test_removing_orphaned_group_relationships(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
group = ifcopenshell.api.run("group.add_group", self.file, name="Unit 1A")
ifcopenshell.api.run("group.assign_group", self.file, products=[element], group=group)
ifcopenshell.api.run("root.remove_product", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
group = ifcopenshell.api.group.add_group(self.file, name="Unit 1A")
ifcopenshell.api.group.assign_group(self.file, products=[element], group=group)
ifcopenshell.api.root.remove_product(self.file, product=element)
assert not self.file.by_type("IfcRelAssignsToGroup")
def test_removing_product_assignments(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
annotation = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcAnnotation")
ifcopenshell.api.run("drawing.assign_product", self.file, relating_product=element, related_object=annotation)
ifcopenshell.api.run("root.remove_product", self.file, product=element)
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
annotation = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcAnnotation")
ifcopenshell.api.drawing.assign_product(self.file, relating_product=element, related_object=annotation)
ifcopenshell.api.root.remove_product(self.file, product=element)
assert not self.file.by_type("IfcRelAssignsToProduct")
def test_removing_flow_control_elements(self):
flow_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
flow_control = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDistributionControlElement")
flow_control1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDistributionControlElement")
flow_element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcFlowSegment")
flow_control = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcDistributionControlElement")
flow_control1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcDistributionControlElement")
ifcopenshell.api.run(
"system.assign_flow_control",
self.file,
related_flow_control=flow_control,
relating_flow_element=flow_element,
ifcopenshell.api.system.assign_flow_control(
self.file, related_flow_control=flow_control, relating_flow_element=flow_element
)
ifcopenshell.api.run(
"system.assign_flow_control",
self.file,
related_flow_control=flow_control1,
relating_flow_element=flow_element,
ifcopenshell.api.system.assign_flow_control(
self.file, related_flow_control=flow_control1, relating_flow_element=flow_element
)
ifcopenshell.api.run("root.remove_product", self.file, product=flow_control)
ifcopenshell.api.root.remove_product(self.file, product=flow_control)
assert len(self.file.by_type("IfcRelFlowControlElements")) == 1
ifcopenshell.api.run("root.remove_product", self.file, product=flow_control1)
ifcopenshell.api.root.remove_product(self.file, product=flow_control1)
assert not self.file.by_type("IfcRelFlowControlElements")
def test_removing_flow_element_with_flow_controls(self):
flow_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
flow_control = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDistributionControlElement")
flow_control1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDistributionControlElement")
flow_element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcFlowSegment")
flow_control = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcDistributionControlElement")
flow_control1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcDistributionControlElement")
ifcopenshell.api.run(
"system.assign_flow_control",
self.file,
related_flow_control=flow_control,
relating_flow_element=flow_element,
ifcopenshell.api.system.assign_flow_control(
self.file, related_flow_control=flow_control, relating_flow_element=flow_element
)
ifcopenshell.api.run(
"system.assign_flow_control",
self.file,
related_flow_control=flow_control1,
relating_flow_element=flow_element,
ifcopenshell.api.system.assign_flow_control(
self.file, related_flow_control=flow_control1, relating_flow_element=flow_element
)
ifcopenshell.api.run("root.remove_product", self.file, product=flow_element)
ifcopenshell.api.root.remove_product(self.file, product=flow_element)
assert not self.file.by_type("IfcRelFlowControlElements")