2022-03-21 17:28:16 +11:00
|
|
|
# IfcOpenShell - IFC toolkit and geometry engine
|
|
|
|
|
# Copyright (C) 2022 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 pytest
|
|
|
|
|
import test.bootstrap
|
|
|
|
|
import ifcopenshell.api
|
|
|
|
|
import ifcopenshell.util.selector as subject
|
2024-03-19 17:01:50 +05:00
|
|
|
import ifcopenshell.util.placement
|
2024-03-21 11:20:57 +05:00
|
|
|
import ifcopenshell.util.pset
|
2024-03-18 17:08:39 +05:00
|
|
|
import numpy as np
|
2022-03-21 17:28:16 +11:00
|
|
|
|
|
|
|
|
|
2023-08-26 15:15:19 +10:00
|
|
|
class TestFormat():
|
|
|
|
|
def test_no_formatting(self):
|
|
|
|
|
assert subject.format("123") == "123"
|
|
|
|
|
assert subject.format('\"123\"') == "123"
|
|
|
|
|
assert subject.format('\"foo\"') == "foo"
|
|
|
|
|
|
|
|
|
|
def test_string_formatting(self):
|
|
|
|
|
assert subject.format('upper(\"fOo\")') == "FOO"
|
|
|
|
|
assert subject.format('lower(\"fOo\")') == "foo"
|
|
|
|
|
assert subject.format('title(\"fOo\")') == "Foo"
|
|
|
|
|
assert subject.format('concat(\"fOo\", \"bar\")') == "fOobar"
|
|
|
|
|
assert subject.format('upper(concat(\"fOo\", \"bar\"))') == "FOOBAR"
|
2023-09-19 18:15:56 +10:00
|
|
|
assert subject.format('substr(\"foobar\", 3)') == "bar"
|
2023-09-07 13:02:45 +10:00
|
|
|
assert subject.format('substr(\"foobar\", 1, 2)') == "o"
|
|
|
|
|
assert subject.format('substr(\"foobar\", 1, -1)') == "ooba"
|
2023-08-26 15:15:19 +10:00
|
|
|
|
|
|
|
|
def test_number_formatting(self):
|
2023-09-19 18:15:56 +10:00
|
|
|
assert subject.format("round(123, 5)") == "125"
|
|
|
|
|
assert subject.format('round(\"123\", 5)') == "125"
|
2024-04-10 17:32:39 +10:00
|
|
|
assert subject.format('number(123)') == "123"
|
|
|
|
|
assert subject.format('number(1234.56)') == "1,234.56"
|
|
|
|
|
assert subject.format('number(123, ".")') == "123"
|
|
|
|
|
assert subject.format('number(\"123\", ".")') == "123"
|
|
|
|
|
assert subject.format('number(123.12, ".")') == "123.12"
|
|
|
|
|
assert subject.format('number(123.12, ",")') == "123,12"
|
|
|
|
|
assert subject.format('number(1234.12, ",", ".")') == "1.234,12"
|
2023-08-26 15:15:19 +10:00
|
|
|
assert subject.format('metric_length(123, 5, 2)') == "125.00"
|
|
|
|
|
assert subject.format('metric_length(123.123, 0.1, 2)') == "123.10"
|
|
|
|
|
assert subject.format('metric_length(\"123\", 5, 2)') == "125.00"
|
|
|
|
|
assert subject.format('imperial_length(1, 1)') == "1'"
|
|
|
|
|
assert subject.format('imperial_length(3.123, 1)') == "3' - 1\""
|
|
|
|
|
assert subject.format('imperial_length(3.123, 2)') == "3' - 1 1/2\""
|
|
|
|
|
assert subject.format('imperial_length(\"3.123\", 2)') == "3' - 1 1/2\""
|
2023-09-07 12:18:32 +10:00
|
|
|
assert subject.format('imperial_length(\"123.123\", 2, \"inch\", \"foot\")') == "10' - 3\""
|
|
|
|
|
assert subject.format('imperial_length(\"123.123\", 2, \"inch\", \"inch\")') == "123\""
|
2023-08-26 15:15:19 +10:00
|
|
|
|
|
|
|
|
|
2023-03-13 11:09:56 +11:00
|
|
|
class TestGetElementValue(test.bootstrap.IFC4):
|
2023-03-27 21:47:11 +11:00
|
|
|
def test_selecting_an_elements_class_or_id_using_a_query(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
assert subject.get_element_value(element, "class") == "IfcWall"
|
|
|
|
|
assert subject.get_element_value(element, "id") == element.id()
|
|
|
|
|
|
2023-03-13 11:09:56 +11:00
|
|
|
def test_selecting_an_elements_value_using_a_query(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element.Name = "Foobar"
|
|
|
|
|
assert subject.get_element_value(element, "Name") == "Foobar"
|
|
|
|
|
|
2023-03-25 22:07:18 +11:00
|
|
|
def test_selecting_using_a_multiple_key_query(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
|
|
|
|
material2 = ifcopenshell.api.run("material.add_material", self.file, name="CON02")
|
|
|
|
|
material_set = ifcopenshell.api.run(
|
|
|
|
|
"material.add_material_set", self.file, name="FOO", set_type="IfcMaterialLayerSet"
|
|
|
|
|
)
|
|
|
|
|
layer = ifcopenshell.api.run("material.add_layer", self.file, layer_set=material_set, material=material)
|
|
|
|
|
layer.Name = "L1"
|
|
|
|
|
layer = ifcopenshell.api.run("material.add_layer", self.file, layer_set=material_set, material=material)
|
|
|
|
|
layer.Name = "L2"
|
|
|
|
|
ifcopenshell.api.run("material.edit_layer", self.file, layer=layer, attributes={"LayerThickness": 13})
|
|
|
|
|
ifcopenshell.api.run("material.assign_material", self.file, product=element, material=material_set)
|
|
|
|
|
assert subject.get_element_value(element, "material.MaterialLayers.Name") == ["L1", "L2"]
|
|
|
|
|
# Allow to use "item" to generically select an item in a material set
|
|
|
|
|
assert subject.get_element_value(element, "material.item.Name") == ["L1", "L2"]
|
2023-04-04 09:58:23 +10:00
|
|
|
assert subject.get_element_value(element, "material.item.Name.0") == "L1"
|
|
|
|
|
assert subject.get_element_value(element, "material.item.Name.1") == "L2"
|
2023-03-25 22:07:18 +11:00
|
|
|
assert subject.get_element_value(element, '"material"."item"."Name"') == ["L1", "L2"]
|
2023-08-26 18:24:48 +10:00
|
|
|
assert subject.get_element_value(element, 'material."item"."Name"') == ["L1", "L2"]
|
2023-03-25 22:07:18 +11:00
|
|
|
# Provide shortform for convenience
|
|
|
|
|
assert subject.get_element_value(element, "mat.i.Name") == ["L1", "L2"]
|
|
|
|
|
|
2023-04-20 17:41:52 +10:00
|
|
|
def test_selecting_a_query_that_fails_silently(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
assert subject.get_element_value(element, "material.item.Name.0") is None
|
|
|
|
|
|
2023-08-26 18:24:48 +10:00
|
|
|
def test_selecting_a_list_item_that_fails_silently(self):
|
2023-04-20 17:41:52 +10:00
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
|
|
|
|
material2 = ifcopenshell.api.run("material.add_material", self.file, name="CON02")
|
|
|
|
|
material_set = ifcopenshell.api.run(
|
|
|
|
|
"material.add_material_set", self.file, name="FOO", set_type="IfcMaterialLayerSet"
|
|
|
|
|
)
|
|
|
|
|
layer = ifcopenshell.api.run("material.add_layer", self.file, layer_set=material_set, material=material)
|
|
|
|
|
layer.Name = "L1"
|
|
|
|
|
ifcopenshell.api.run("material.assign_material", self.file, product=element, material=material_set)
|
|
|
|
|
assert subject.get_element_value(element, "material.item.Name.0") == "L1"
|
|
|
|
|
assert subject.get_element_value(element, "material.item.Name.1") is None
|
|
|
|
|
|
2023-08-26 18:24:48 +10:00
|
|
|
def test_selecting_a_pset(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element2 = 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"})
|
|
|
|
|
assert subject.get_element_value(element, "Foobar.Foo") == "Bar"
|
|
|
|
|
assert subject.get_element_value(element, "Foobar./F.*/") == "Bar"
|
|
|
|
|
assert subject.get_element_value(element, "/Foo.*/./F.*/") == "Bar"
|
|
|
|
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Baz": 123})
|
|
|
|
|
assert subject.get_element_value(element, "/Foo.*/./B.*/") == 123
|
|
|
|
|
assert subject.get_element_value(element, "/Foo.*/./.*/") == ["Bar", 123]
|
|
|
|
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Bay": 123.3})
|
|
|
|
|
assert subject.get_element_value(element, "/Foo.*/./B.*/") == [123, 123.3]
|
|
|
|
|
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon")
|
|
|
|
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Status": ["New"]})
|
|
|
|
|
assert subject.get_element_value(element, "/Pset_.*Common/.Status") == ["New"]
|
|
|
|
|
assert subject.get_element_value(element, "/Pset_.*Common/.Status.0") == "New"
|
|
|
|
|
|
2023-03-13 11:09:56 +11:00
|
|
|
|
2023-07-20 19:22:15 +10:00
|
|
|
class TestFilterElements(test.bootstrap.IFC4):
|
2023-07-20 19:42:34 +10:00
|
|
|
def test_selecting_by_globalid(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
|
|
|
|
guid1 = element.GlobalId
|
|
|
|
|
guid2 = element2.GlobalId
|
|
|
|
|
assert subject.filter_elements(self.file, f"{guid1}") == {element}
|
|
|
|
|
assert subject.filter_elements(self.file, f"{guid1}, {guid2}") == {element, element2}
|
|
|
|
|
assert subject.filter_elements(self.file, f"{guid1}, {guid2}, ! {guid2}") == {element}
|
|
|
|
|
assert subject.filter_elements(self.file, f"IfcElement, ! {guid2}") == {element}
|
|
|
|
|
|
2023-07-20 19:22:15 +10:00
|
|
|
def test_selecting_by_class(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element.Name = "Foo"
|
|
|
|
|
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall") == {element}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcElement, ! IfcWall") == {element2}
|
|
|
|
|
|
|
|
|
|
def test_selecting_by_attribute(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element.Name = "Foo"
|
|
|
|
|
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element2.Name = "Bar"
|
|
|
|
|
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Name=Foo") == {element}
|
|
|
|
|
element.Name = 'Foo\'s "quoted" name...'
|
|
|
|
|
assert subject.filter_elements(self.file, 'IfcWall, Name="Foo\'s \\"quoted\\" name..."') == {element}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Name=/Fo.*/") == {element}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Description=NULL") == {element, element2}
|
2023-09-06 16:34:39 +10:00
|
|
|
element.Name = "Foo"
|
|
|
|
|
element.Description = "Foobar"
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Name=Foo, Description=Foobar") == {element}
|
2023-07-20 19:22:15 +10:00
|
|
|
|
|
|
|
|
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")
|
2024-04-10 17:18:37 +05:00
|
|
|
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
|
2023-07-20 19:22:15 +10:00
|
|
|
assert subject.filter_elements(self.file, "IfcWall, type=Foo") == set()
|
|
|
|
|
element_type.Name = "Foo"
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, type=Foo") == {element}
|
|
|
|
|
assert subject.filter_elements(self.file, 'IfcWall, type="Foo"') == {element}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, type=/Fo.*/") == {element}
|
|
|
|
|
|
|
|
|
|
def test_selecting_by_material(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, material=NULL") == {element, element2}
|
|
|
|
|
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
|
|
|
|
ifcopenshell.api.run("material.assign_material", self.file, product=element, material=material)
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, material=CON01") == {element}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, material!=CON01") == {element2}
|
|
|
|
|
|
|
|
|
|
def test_selecting_by_property(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element2 = 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"})
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Foobar.Foo=Bar") == {element}
|
|
|
|
|
assert subject.filter_elements(self.file, 'IfcWall, Foobar."Foo"=Bar') == {element}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Foobar./Fo.*/=Bar") == {element}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Foobar./Fo.*/!=Bar") == {element2}
|
|
|
|
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Bar": False})
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Foobar.Bar=FALSE") == {element}
|
|
|
|
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Baz": 123})
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Foobar.Baz=123") == {element}
|
|
|
|
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Bay": 123.3})
|
2023-08-15 09:55:48 +10:00
|
|
|
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon")
|
|
|
|
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Status": ["New"]})
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Pset_WallCommon.Status=New") == {element}
|
2023-07-20 19:22:15 +10:00
|
|
|
|
2024-01-13 15:58:57 +11:00
|
|
|
def test_selecting_by_property_with_comparisons(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element2 = 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={"Baz": 123})
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Foobar.Baz>100") == {element}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Foobar.Baz<100") == set()
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Foobar.Baz>=100") == {element}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Foobar.Baz<=100") == set()
|
|
|
|
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": "Bar"})
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Foobar.Foo*=ar") == {element}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Foobar.Foo!*=ar") == {element2}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Foobar.Foo*=Foo") == set()
|
|
|
|
|
|
2023-07-20 19:22:15 +10:00
|
|
|
def test_selecting_by_classification(self):
|
|
|
|
|
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, classification=NULL") == {element, element2}
|
|
|
|
|
result = ifcopenshell.api.run("classification.add_classification", self.file, classification="Name")
|
|
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"classification.add_reference",
|
|
|
|
|
self.file,
|
|
|
|
|
product=element,
|
|
|
|
|
identification="X",
|
|
|
|
|
name="Foobar",
|
|
|
|
|
classification=result,
|
|
|
|
|
)
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, classification=NULL") == {element2}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, classification=X") == {element}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, classification=Foobar") == {element}
|
|
|
|
|
|
|
|
|
|
def test_selecting_by_location(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
space = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSpace", name="Space")
|
|
|
|
|
storey = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuildingStorey", name="G")
|
|
|
|
|
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding", name="Building")
|
|
|
|
|
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject", name="Project")
|
2024-04-05 14:57:11 +05:00
|
|
|
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=space)
|
|
|
|
|
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element2], relating_structure=storey)
|
2024-04-08 16:23:48 +05:00
|
|
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[space], relating_object=storey)
|
|
|
|
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[storey], relating_object=building)
|
|
|
|
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[building], relating_object=project)
|
2023-07-20 19:22:15 +10:00
|
|
|
assert subject.filter_elements(self.file, "IfcWall, location=NULL") == set()
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, location=Space") == {element}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, location=G") == {element, element2}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, location=Building") == {element, element2}
|
|
|
|
|
|
|
|
|
|
def test_selecting_multiple_filter_groups(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element.Name = "Foo"
|
|
|
|
|
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
|
|
|
|
element2.Name = "Bar"
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall + IfcSlab") == {element, element2}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, IfcSlab, Name=Foo") == {element}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Name=Foo + IfcSlab") == {element, element2}
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, Name=Foo + IfcSlab, Name=Bar") == {element, element2}
|
|
|
|
|
|
2024-03-13 15:21:46 +05:00
|
|
|
def test_using_elements_argument(self):
|
|
|
|
|
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
slab = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
|
|
|
|
|
|
|
|
|
# keep elements unaffected by expression
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall", {slab}) == {wall, slab}
|
|
|
|
|
|
|
|
|
|
# filter out excluded elements
|
|
|
|
|
assert subject.filter_elements(self.file, "IfcWall, ! IfcSlab", {slab}) == {wall}
|
|
|
|
|
|
|
|
|
|
# edit_in_place to update original set
|
|
|
|
|
original_set = set()
|
|
|
|
|
new_set = subject.filter_elements(self.file, "IfcWall", original_set, edit_in_place=True)
|
|
|
|
|
assert new_set == original_set
|
|
|
|
|
|
2023-07-20 19:22:15 +10:00
|
|
|
|
2024-03-18 16:37:43 +05:00
|
|
|
class TestSetElementValue(test.bootstrap.IFC4):
|
|
|
|
|
def test_set_xyz_coordinates(self):
|
|
|
|
|
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
|
|
|
|
ifcopenshell.api.run("unit.assign_unit", self.file)
|
2024-03-19 17:01:50 +05:00
|
|
|
|
|
|
|
|
items = list(zip("xyz", ("5", "10", "15")))
|
|
|
|
|
matrix = np.eye(4)
|
|
|
|
|
matrix[:, 3] = (5, 10, 15, 1)
|
|
|
|
|
|
2024-03-18 16:37:43 +05:00
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=element, is_si=False)
|
2024-03-19 17:01:50 +05:00
|
|
|
for coord, value in items:
|
2024-03-18 16:37:43 +05:00
|
|
|
subject.set_element_value(self.file, element, coord, value)
|
|
|
|
|
assert np.array_equal(ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement), matrix)
|
|
|
|
|
|
2024-03-19 17:01:50 +05:00
|
|
|
element_without_placement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
for coord, value in items:
|
|
|
|
|
subject.set_element_value(self.file, element_without_placement, coord, value)
|
|
|
|
|
assert np.array_equal(
|
|
|
|
|
ifcopenshell.util.placement.get_local_placement(element_without_placement.ObjectPlacement), matrix
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-29 20:37:22 +11:00
|
|
|
def test_set_attribute(self):
|
|
|
|
|
element = self.file.createIfcWall()
|
|
|
|
|
subject.set_element_value(self.file, element, "Name", "Foo")
|
|
|
|
|
assert element.Name == "Foo"
|
|
|
|
|
subject.set_element_value(self.file, element, "Name", 123)
|
|
|
|
|
assert element.Name == "123"
|
|
|
|
|
|
2024-03-18 16:37:43 +05:00
|
|
|
|
2022-03-21 17:28:16 +11:00
|
|
|
class TestSelector(test.bootstrap.IFC4):
|
2024-03-21 11:20:57 +05:00
|
|
|
def test_selecting_from_specified_elements(self):
|
|
|
|
|
elements = [ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") for _ in range(2)]
|
|
|
|
|
assert subject.Selector.parse(self.file, ".IfcWall", elements[:1]) == [elements[0]]
|
|
|
|
|
|
2022-03-21 17:28:16 +11:00
|
|
|
def test_selecting_by_class(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
|
|
|
|
assert subject.Selector.parse(self.file, ".IfcWall") == [element]
|
|
|
|
|
|
|
|
|
|
def test_selecting_by_globalid(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
|
|
|
|
assert subject.Selector.parse(self.file, f"#{element.GlobalId}") == [element]
|
|
|
|
|
|
2022-04-27 22:19:31 +10:00
|
|
|
def test_selecting_by_attribute_existence(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element.Name = "Foobar"
|
|
|
|
|
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
2022-08-19 20:10:54 +10:00
|
|
|
assert subject.Selector.parse(self.file, ".IfcElement[Name]") == [element]
|
|
|
|
|
assert subject.Selector.parse(self.file, ".IfcElement[Description]") == []
|
2022-04-27 22:19:31 +10:00
|
|
|
|
2022-03-21 17:28:16 +11:00
|
|
|
def test_selecting_by_attribute(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element.Name = "Foobar"
|
|
|
|
|
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
|
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement[Name="Foobar"]') == [element]
|
|
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement[Name="Foobaz"]') == []
|
|
|
|
|
|
2023-05-31 13:23:40 +10:00
|
|
|
def test_selecting_by_regex(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element.Name = "Foobar"
|
|
|
|
|
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
|
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement[Name=r"Foo.*"]') == [element]
|
|
|
|
|
|
2022-04-27 22:19:31 +10:00
|
|
|
def test_selecting_by_property_existence(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"})
|
2022-08-19 20:10:54 +10:00
|
|
|
assert subject.Selector.parse(self.file, ".IfcElement[Foo_Bar.Foo]") == [element]
|
|
|
|
|
assert subject.Selector.parse(self.file, ".IfcElement[Foo_Bar.Fox]") == []
|
2023-04-06 19:21:14 +10:00
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement[r"Foo.*ar"."Fo.*"]') == [element]
|
2022-04-27 22:19:31 +10:00
|
|
|
|
2022-03-21 17:28:16 +11:00
|
|
|
def test_selecting_by_string_property(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"})
|
|
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo="Bar"]') == [element]
|
2022-03-21 18:03:25 +11:00
|
|
|
|
2022-08-19 20:10:54 +10:00
|
|
|
def test_selecting_by_enumerated_property(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="Pset_WallCommon")
|
|
|
|
|
template = ifcopenshell.util.pset.get_template("IFC4").get_by_name("Pset_WallCommon")
|
|
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"pset.edit_pset", self.file, pset=pset, properties={"Status": ["NEW"]}, pset_template=template
|
|
|
|
|
)
|
|
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement[Pset_WallCommon.Status="NEW"]') == [element]
|
|
|
|
|
|
2022-03-21 18:03:25 +11:00
|
|
|
def test_selecting_by_integer_property(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": 42})
|
2022-03-22 11:23:13 +11:00
|
|
|
assert subject.Selector.parse(self.file, ".IfcElement[Foo_Bar.Foo=42]") == [element]
|
2022-03-21 18:03:25 +11:00
|
|
|
|
|
|
|
|
def test_selecting_by_float_property(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": 4.2})
|
2022-03-22 11:23:13 +11:00
|
|
|
assert subject.Selector.parse(self.file, ".IfcElement[Foo_Bar.Foo=4.2]") == [element]
|
2022-03-21 18:03:25 +11:00
|
|
|
|
|
|
|
|
def test_selecting_by_boolean_property(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": True})
|
2022-03-22 11:23:13 +11:00
|
|
|
assert subject.Selector.parse(self.file, ".IfcElement[Foo_Bar.Foo=TRUE]") == [element]
|
2022-03-21 18:03:25 +11:00
|
|
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": False})
|
2022-03-22 11:23:13 +11:00
|
|
|
assert subject.Selector.parse(self.file, ".IfcElement[Foo_Bar.Foo=FALSE]") == [element]
|
2022-03-21 18:03:25 +11:00
|
|
|
|
|
|
|
|
def test_selecting_by_null_property(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"})
|
2022-03-22 11:23:13 +11:00
|
|
|
assert subject.Selector.parse(self.file, ".IfcElement[Foo_Bar.Foo=NULL]") == []
|
2022-03-21 18:03:25 +11:00
|
|
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": None})
|
2022-03-22 11:23:13 +11:00
|
|
|
assert subject.Selector.parse(self.file, ".IfcElement[Foo_Bar.Foo=NULL]") == [element]
|
2022-03-22 10:40:05 +11:00
|
|
|
|
|
|
|
|
def test_comparing_by_not_equal(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element.Name = "Foobar"
|
|
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement[Name!="Foobaz"]') == [element]
|
|
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement[Name!="Foobar"]') == []
|
|
|
|
|
|
|
|
|
|
def test_comparing_by_ranges(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": 4.2})
|
2022-03-22 11:23:13 +11:00
|
|
|
assert subject.Selector.parse(self.file, ".IfcElement[Foo_Bar.Foo>2]") == [element]
|
|
|
|
|
assert subject.Selector.parse(self.file, ".IfcElement[Foo_Bar.Foo>20]") == []
|
|
|
|
|
assert subject.Selector.parse(self.file, ".IfcElement[Foo_Bar.Foo<2]") == []
|
|
|
|
|
assert subject.Selector.parse(self.file, ".IfcElement[Foo_Bar.Foo<20]") == [element]
|
|
|
|
|
assert subject.Selector.parse(self.file, ".IfcElement[Foo_Bar.Foo>=4.2]") == [element]
|
|
|
|
|
assert subject.Selector.parse(self.file, ".IfcElement[Foo_Bar.Foo<=4.2]") == [element]
|
2022-03-22 10:49:48 +11:00
|
|
|
|
|
|
|
|
def test_comparing_if_value_contains_a_wildcard_string(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element.Name = "Foobar"
|
|
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement[Name*="Foo"]') == [element]
|
|
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement[Name*="oba"]') == [element]
|
|
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement[Name*="abc"]') == []
|
2022-07-20 09:06:04 +02:00
|
|
|
|
2022-07-20 09:33:58 +02:00
|
|
|
def test_selecting_if_value_not_matching(self):
|
2022-07-20 09:06:04 +02:00
|
|
|
element_1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element_2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
pset_1 = ifcopenshell.api.run("pset.add_pset", self.file, product=element_1, name="Foo_Bar")
|
|
|
|
|
pset_2 = ifcopenshell.api.run("pset.add_pset", self.file, product=element_2, name="Foo_Bar")
|
|
|
|
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset_1, properties={"Foo": "Bar"})
|
|
|
|
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset_2, properties={"Foo": "BOO"})
|
2023-10-10 17:33:00 +11:00
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement["Foo_Bar"."Foo" != "Bar"]') == [element_2]
|
|
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement["Foo_Bar"."Foo" != "BOO"]') == [element_1]
|
2022-07-20 09:33:58 +02:00
|
|
|
|
|
|
|
|
def test_selecting_when_attribute_is_none(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
2022-08-19 20:10:54 +10:00
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement[PredefinedType !="non-existent predefined type"]') == [
|
|
|
|
|
element
|
|
|
|
|
]
|
|
|
|
|
|
2022-07-20 08:32:36 +02:00
|
|
|
def test_selecting_a_property_which_includes_non_standard_characters(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="a !%$§&/()?|*-+,€~#@µ^°a")
|
|
|
|
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a !%$§&/()?|*-+,€~#@µ^°a": "Bar"})
|
2022-08-19 20:10:54 +10:00
|
|
|
assert subject.Selector.parse(
|
2023-03-25 22:07:18 +11:00
|
|
|
self.file, '.IfcElement["a !%$§&/()?|*-+,€~#@µ^°a"."a !%$§&/()?|*-+,€~#@µ^°a"="Bar"]'
|
2022-08-19 20:10:54 +10:00
|
|
|
) == [element]
|
2022-03-22 10:49:48 +11:00
|
|
|
|
2023-03-06 17:47:03 +11:00
|
|
|
def test_selecting_a_property_which_includes_a_dot(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="a.b")
|
|
|
|
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"c.d": "Bar"})
|
|
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement["a.b"."c.d"="Bar"]') == [element]
|
|
|
|
|
|
|
|
|
|
def test_selecting_a_property_which_includes_an_escaped_quote(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='"a.b"')
|
|
|
|
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={'"c.d"': "Bar"})
|
|
|
|
|
assert subject.Selector.parse(self.file, r'.IfcElement["\"a.b\""."\"c.d\""="Bar"]') == [element]
|
|
|
|
|
|
2022-03-22 10:49:48 +11:00
|
|
|
def test_comparing_if_value_is_in_a_list(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element.Name = "Foobar"
|
|
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement[Name%="Foobar,Foobaz"]') == [element]
|
|
|
|
|
element.Name = "Foobaz"
|
|
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement[Name%="Foobar,Foobaz"]') == [element]
|
|
|
|
|
element.Name = "Foobat"
|
|
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement[Name%="Foobar,Foobaz"]') == []
|
2022-03-22 11:23:13 +11:00
|
|
|
|
|
|
|
|
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")
|
2024-04-10 17:18:37 +05:00
|
|
|
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
|
2022-03-22 11:23:13 +11:00
|
|
|
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
2022-03-22 11:32:40 +11:00
|
|
|
element_type2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
2024-04-10 17:18:37 +05:00
|
|
|
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element2], relating_type=element_type2)
|
2022-03-22 11:32:40 +11:00
|
|
|
assert set(subject.Selector.parse(self.file, "* .IfcWallType")) == {element, element2}
|
2022-03-22 11:23:13 +11:00
|
|
|
|
|
|
|
|
def test_getting_decomposition_of_a_filtered_type(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcMember")
|
|
|
|
|
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
2024-04-05 14:57:11 +05:00
|
|
|
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=building)
|
2024-04-08 16:23:48 +05:00
|
|
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
2022-03-22 11:32:40 +11:00
|
|
|
assert set(subject.Selector.parse(self.file, "@ .IfcBuilding")) == {element, subelement}
|
|
|
|
|
|
|
|
|
|
def test_selecting_elements_from_a_prefiltered_list(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
|
|
|
|
assert subject.Selector.parse(self.file, ".IfcWall", elements=[element])
|
|
|
|
|
assert not subject.Selector.parse(self.file, ".IfcWall", elements=[element2])
|
2023-03-09 11:07:13 +11:00
|
|
|
|
|
|
|
|
def test_selecting_a_property_via_a_wildcard_pset_name(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"})
|
|
|
|
|
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foobaz")
|
|
|
|
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": "Baz"})
|
|
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement[r"Foo.*"."Foo"="Bar"]') == [element]
|
|
|
|
|
|
|
|
|
|
def test_selecting_a_property_via_a_wildcard_property_name(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"})
|
|
|
|
|
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foobaz")
|
|
|
|
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": "Baz"})
|
|
|
|
|
assert subject.Selector.parse(self.file, '.IfcElement[r"Foo.*"."F.*"="Bar"]') == [element]
|
|
|
|
|
|
2023-03-25 22:07:18 +11:00
|
|
|
def test_selecting_an_attribute_via_a_type(self):
|
2023-03-09 11:07:13 +11:00
|
|
|
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"
|
2024-04-10 17:18:37 +05:00
|
|
|
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
|
2023-03-09 11:07:13 +11:00
|
|
|
assert set(subject.Selector.parse(self.file, '.IfcWall[type.Name="Foo"]')) == {element}
|
2023-03-25 22:07:18 +11:00
|
|
|
|
|
|
|
|
def test_selecting_via_a_material(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
|
|
|
|
ifcopenshell.api.run("material.assign_material", self.file, product=element, material=material)
|
|
|
|
|
assert set(subject.Selector.parse(self.file, '.IfcWall[material.Name="CON01"]')) == {element}
|
|
|
|
|
|
|
|
|
|
def test_selecting_via_a_material_set(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
|
|
|
|
material_set = ifcopenshell.api.run(
|
|
|
|
|
"material.add_material_set", self.file, name="FOO", set_type="IfcMaterialLayerSet"
|
|
|
|
|
)
|
|
|
|
|
layer = ifcopenshell.api.run("material.add_layer", self.file, layer_set=material_set, material=material)
|
|
|
|
|
ifcopenshell.api.run("material.edit_layer", self.file, layer=layer, attributes={"LayerThickness": 13})
|
|
|
|
|
ifcopenshell.api.run("material.assign_material", self.file, product=element, material=material_set)
|
|
|
|
|
assert set(subject.Selector.parse(self.file, '.IfcWall[material.LayerSetName="FOO"]')) == {element}
|
|
|
|
|
|
|
|
|
|
def test_selecting_via_a_material_set_item(self):
|
|
|
|
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
|
|
|
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
|
|
|
|
material2 = ifcopenshell.api.run("material.add_material", self.file, name="CON02")
|
|
|
|
|
material_set = ifcopenshell.api.run(
|
|
|
|
|
"material.add_material_set", self.file, name="FOO", set_type="IfcMaterialLayerSet"
|
|
|
|
|
)
|
|
|
|
|
layer = ifcopenshell.api.run("material.add_layer", self.file, layer_set=material_set, material=material)
|
|
|
|
|
layer = ifcopenshell.api.run("material.add_layer", self.file, layer_set=material_set, material=material2)
|
|
|
|
|
ifcopenshell.api.run("material.assign_material", self.file, product=element, material=material_set)
|
|
|
|
|
assert set(subject.Selector.parse(self.file, '.IfcWall[material.item.Material.Name="CON01"]')) == {element}
|
|
|
|
|
assert set(subject.Selector.parse(self.file, '.IfcWall[material.item.Material.Name="CON02"]')) == {element}
|
|
|
|
|
assert set(subject.Selector.parse(self.file, '.IfcWall[material.item.Material.Name="CON03"]')) == set()
|