mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 10:11:46 +00:00
#2082 You can now filter by metadata existence in the selector syntax
This commit is contained in:
@@ -321,8 +321,8 @@ class CopyRepresentation(bpy.types.Operator, Operator):
|
|||||||
|
|
||||||
class OverrideDeleteTrait:
|
class OverrideDeleteTrait:
|
||||||
def delete_ifc_object(self, obj):
|
def delete_ifc_object(self, obj):
|
||||||
if obj.BIMObjectProperties.ifc_definition_id:
|
element = tool.Ifc.get_entity(obj)
|
||||||
element = IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id)
|
if element:
|
||||||
IfcStore.delete_element(element)
|
IfcStore.delete_element(element)
|
||||||
if getattr(element, "FillsVoids", None):
|
if getattr(element, "FillsVoids", None):
|
||||||
self.remove_filling(element)
|
self.remove_filling(element)
|
||||||
|
|||||||
@@ -192,7 +192,9 @@ class Selector:
|
|||||||
element_value = cls.get_element_value(element, key)
|
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:
|
||||||
continue
|
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)
|
results.append(element)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,13 @@ class TestSelector(test.bootstrap.IFC4):
|
|||||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
||||||
assert subject.Selector.parse(self.file, f"#{element.GlobalId}") == [element]
|
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):
|
def test_selecting_by_attribute(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
element.Name = "Foobar"
|
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="Foobar"]') == [element]
|
||||||
assert subject.Selector.parse(self.file, '.IfcElement[Name="Foobaz"]') == []
|
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):
|
def test_selecting_by_string_property(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
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")
|
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")
|
||||||
|
|||||||
Reference in New Issue
Block a user