ifcopenshell.util.selector

Module Contents

class ifcopenshell.util.selector.FacetTransformer(ifc_file: ifcopenshell.file, elements: set[ifcopenshell.entity_instance] | None = None)

Bases: lark.Transformer

attribute(args)
classification(args)
compare(element_value, comparison, value)
comparison(args)
entity(args)
facet_list(args)
get_container_tree(container)
get_results()
group(args)
instance(args)
keys(args)
location(args)
material(args)
prop(args)
property(args)
pset(args)
query(args)
type(args)
value(args)
class ifcopenshell.util.selector.FormatTransformer

Bases: lark.Transformer

ESCAPED_STRING(args)
NUMBER(args)
concat(args)
format_length(args)
function(args)
imperial_length(args)
lower(args)
metric_length(args)
number(args)
round(args)
start(args)
substr(args)
title(args)
upper(args)
class ifcopenshell.util.selector.GetElementTransformer

Bases: lark.Transformer

ESCAPED_STRING(args)
key(args)
keys(args)
quoted_string(args)
regex_string(args)
start(args)
unquoted_string(args)
class ifcopenshell.util.selector.Selector
classmethod filter_element(element, element_value, comparison, value, is_regex=False)
classmethod filter_elements(elements, filter_rule)
classmethod get_class_selector(class_selector)
classmethod get_element_value(element: ifcopenshell.entity_instance, keys: list[str]) Any
classmethod get_group(group)
classmethod get_guid_selector(guid_selector)
classmethod get_query(query)
classmethod get_selector(selector)
classmethod parse(ifc_file: ifcopenshell.file, query: str, elements: list[ifcopenshell.entity_instance] | None = None) list[ifcopenshell.entity_instance]
classmethod parse_filter_query(filter_query)
classmethod parse_inverse_relationship(elements, inverse_relationship)
ifcopenshell.util.selector.filter_elements(ifc_file: ifcopenshell.file, query: str, elements: set[ifcopenshell.entity_instance] | None = None, edit_in_place=False) set[ifcopenshell.entity_instance]

Filter elements based on the provided query.

Parameters:
  • ifc_file (ifcopenshell.file) – The IFC file object

  • query (str) – Query to execute

  • elements (set[ifcopenshell.entity_instance], optional) – Base set of IFC elements for the query. If provided, new elements found for the current query will be added to elements. Elements explicitly excluded in the query will also be excluded from elements

  • edit_in_place (bool) – If True, mutate the provided elements in place. Defaults to False

Returns:

Set of filtered elements

Return type:

set[ifcopenshell.entity_instance]

Example:

# Select all walls in the file.
elements = ifcopenshell.util.selector.filter_elements(ifc_file, "IfcWall, IfcSlab")

# Add doors to the elements too.
elements = ifcopenshell.util.selector.filter_elements(ifc_file, "IfcDoor", elements)

# Changed our mind, exclude the slabs.
elements = ifcopenshell.util.selector.filter_elements(ifc_file, "! IfcSlab", elements)

# {#1=IfcWall(...), #2=IfcDoor(...)}
print(elements)
ifcopenshell.util.selector.format(query: str) str
ifcopenshell.util.selector.get_element_value(element: ifcopenshell.entity_instance, query: str) Any
ifcopenshell.util.selector.set_element_value(ifc_file: ifcopenshell.file, element: ifcopenshell.entity_instance, query: str | list[str], value: str | None) ifcopenshell.entity_instance | None
ifcopenshell.util.selector.filter_elements_grammar
ifcopenshell.util.selector.format_grammar
ifcopenshell.util.selector.get_element_grammar