diff --git a/src/ifcopenshell-python/ifcopenshell/util/selector.py b/src/ifcopenshell-python/ifcopenshell/util/selector.py index 1dcb9a0ba0..52c7176650 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/selector.py +++ b/src/ifcopenshell-python/ifcopenshell/util/selector.py @@ -660,7 +660,7 @@ class FacetTransformer(lark.Transformer): containers = self.get_container_tree(container) result = False if containers else None for container in containers: - if self.compare(container.Name, comparison, value): + if self.compare(container.Name, "=", value): result = True if result is not None: return result if comparison == "=" else not result @@ -675,7 +675,7 @@ class FacetTransformer(lark.Transformer): result = False for rel in getattr(element, "HasAssignments", []): if rel.is_a("IfcRelAssignsToGroup") and rel.RelatingGroup: - if self.compare(rel.RelatingGroup.Name, comparison, value): + if self.compare(rel.RelatingGroup.Name, "=", value): result = True return result if comparison == "=" else not result diff --git a/src/ifcopenshell-python/test/util/test_selector.py b/src/ifcopenshell-python/test/util/test_selector.py index efcc5dfa9c..e361833b34 100644 --- a/src/ifcopenshell-python/test/util/test_selector.py +++ b/src/ifcopenshell-python/test/util/test_selector.py @@ -238,6 +238,7 @@ class TestFilterElements(test.bootstrap.IFC4): 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} + assert subject.filter_elements(self.file, "IfcWall, classification!=X") == {element2} def test_selecting_by_location(self): element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") @@ -255,6 +256,15 @@ class TestFilterElements(test.bootstrap.IFC4): 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} + assert subject.filter_elements(self.file, "IfcWall, location!=Space") == {element2} + + def test_selecting_by_group(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") + group = ifcopenshell.api.run("group.add_group", self.file, name="Foo") + ifcopenshell.api.run("group.assign_group", self.file, products=[element], group=group) + assert subject.filter_elements(self.file, "IfcWall, group=Foo") == {element} + assert subject.filter_elements(self.file, "IfcWall, group!=Foo") == {element2} def test_selecting_multiple_filter_groups(self): element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")