MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / filter

Method filter

src/ifctester/ifctester/facet.py:199–228  ·  view source on GitHub ↗
(
        self, ifc_file: ifcopenshell.file, elements: Optional[list[ifcopenshell.entity_instance]] = None
    )

Source from the content-addressed store, hash-verified

197 super().__init__(name, predefinedType, instructions)
198
199 def filter(
200 self, ifc_file: ifcopenshell.file, elements: Optional[list[ifcopenshell.entity_instance]] = None
201 ) -> list[ifcopenshell.entity_instance]:
202 if isinstance(elements, list):
203 return super().filter(ifc_file, elements)
204
205 if isinstance(self.name, str):
206 try:
207 results = ifc_file.by_type(self.name, include_subtypes=False)
208 except:
209 # If the user has specified a class that doesn't exist in the version
210 results = []
211 if not self.name.endswith("TYPE"):
212 try:
213 for element_type in ifc_file.by_type(f"{self.name}Type"):
214 results.extend(ifcopenshell.util.element.get_types(element_type))
215 except:
216 pass
217 else:
218 results = []
219 ifc_classes = [t for t in ifc_file.wrapped_data.types() if t.upper() == self.name]
220 for ifc_class in ifc_classes:
221 try:
222 results.extend(ifc_file.by_type(ifc_class, include_subtypes=False))
223 except:
224 # If the user has specified a class that doesn't exist in the version
225 continue
226 if self.predefinedType:
227 return [r for r in results if self(r)]
228 return results
229
230 def __call__(self, inst: ifcopenshell.entity_instance, logger: Optional[Logger] = None) -> EntityResult:
231 is_pass = inst.is_a().upper() == self.name

Calls 4

upperMethod · 0.80
filterMethod · 0.45
by_typeMethod · 0.45
extendMethod · 0.45

Tested by 1