diff --git a/src/blenderbim/blenderbim/bim/module/geometry/operator.py b/src/blenderbim/blenderbim/bim/module/geometry/operator.py index 376660a96b..a8ba8566d5 100644 --- a/src/blenderbim/blenderbim/bim/module/geometry/operator.py +++ b/src/blenderbim/blenderbim/bim/module/geometry/operator.py @@ -321,8 +321,8 @@ class CopyRepresentation(bpy.types.Operator, Operator): class OverrideDeleteTrait: def delete_ifc_object(self, obj): - if obj.BIMObjectProperties.ifc_definition_id: - element = IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id) + element = tool.Ifc.get_entity(obj) + if element: IfcStore.delete_element(element) if getattr(element, "FillsVoids", None): self.remove_filling(element) diff --git a/src/ifcopenshell-python/ifcopenshell/util/selector.py b/src/ifcopenshell-python/ifcopenshell/util/selector.py index 910f287647..c8b7a2eb91 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/selector.py +++ b/src/ifcopenshell-python/ifcopenshell/util/selector.py @@ -192,7 +192,9 @@ class Selector: element_value = cls.get_element_value(element, key) if element_value is None and value is not None: continue - if not comparison or cls.filter_element(element, element_value, comparison, value): + if comparison and cls.filter_element(element, element_value, comparison, value): + results.append(element) + elif not comparison and element_value: results.append(element) return results diff --git a/src/ifcopenshell-python/test/util/test_selector.py b/src/ifcopenshell-python/test/util/test_selector.py index 3c138098cc..37a744e6e4 100644 --- a/src/ifcopenshell-python/test/util/test_selector.py +++ b/src/ifcopenshell-python/test/util/test_selector.py @@ -33,6 +33,13 @@ class TestSelector(test.bootstrap.IFC4): ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab") assert subject.Selector.parse(self.file, f"#{element.GlobalId}") == [element] + 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") + assert subject.Selector.parse(self.file, '.IfcElement[Name]') == [element] + assert subject.Selector.parse(self.file, '.IfcElement[Description]') == [] + def test_selecting_by_attribute(self): element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") element.Name = "Foobar" @@ -40,6 +47,13 @@ class TestSelector(test.bootstrap.IFC4): assert subject.Selector.parse(self.file, '.IfcElement[Name="Foobar"]') == [element] assert subject.Selector.parse(self.file, '.IfcElement[Name="Foobaz"]') == [] + 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"}) + assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo]') == [element] + assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Fox]') == [] + 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")