diff --git a/src/ifcopenshell-python/ifcopenshell/util/selector.py b/src/ifcopenshell-python/ifcopenshell/util/selector.py index fb98c7a87d..fd4b790350 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/selector.py +++ b/src/ifcopenshell-python/ifcopenshell/util/selector.py @@ -189,7 +189,7 @@ class Selector: value = None for element in elements: element_value = cls.get_element_value(element, key) - if element_value is None and value is not None: + if element_value is None and value is not None and "not" not in comparison: continue if comparison and cls.filter_element(element, element_value, comparison, value): results.append(element) diff --git a/src/ifcopenshell-python/test/util/test_selector.py b/src/ifcopenshell-python/test/util/test_selector.py index ccbf60b443..787b4b2b60 100644 --- a/src/ifcopenshell-python/test/util/test_selector.py +++ b/src/ifcopenshell-python/test/util/test_selector.py @@ -112,7 +112,7 @@ class TestSelector(test.bootstrap.IFC4): assert subject.Selector.parse(self.file, '.IfcElement[Name*="oba"]') == [element] assert subject.Selector.parse(self.file, '.IfcElement[Name*="abc"]') == [] - def test_comparing_if_value_does_not_exist(self): + def test_selecting_if_value_not_matching(self): 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") @@ -122,6 +122,11 @@ class TestSelector(test.bootstrap.IFC4): 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] + + def test_selecting_when_attribute_is_none(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + assert subject.Selector.parse(self.file, '.IfcElement[PredefinedType !="non-existent predefined type"]') == [element] + 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")