ifcopenshell.util.selector¶
Module Contents¶
- exception ifcopenshell.util.selector.SetElementValueException¶
Bases:
ExceptionCommon base class for all non-exit exceptions.
Initialize self. See help(type(self)) for accurate signature.
- class ifcopenshell.util.selector.FacetTransformer(ifc_file: ifcopenshell.file, elements: set[ifcopenshell.entity_instance] | None = None)¶
Bases:
lark.Transformer- add_default_elements()¶
- attribute(args)¶
- classification(args)¶
- compare(element_value, comparison, value) bool¶
- comparison(args)¶
- entity(args)¶
- facet_list(args)¶
- get_container_tree(container: ifcopenshell.entity_instance) list[ifcopenshell.entity_instance]¶
- get_results() set[ifcopenshell.entity_instance]¶
- group(args)¶
- instance(args)¶
- keys(args)¶
- location(args)¶
- material(args)¶
- parent(args)¶
- prop(args)¶
- property(args)¶
- pset(args)¶
- query(args)¶
- type(args)¶
- value(args)¶
- base_elements: set[ifcopenshell.entity_instance] | None¶
- container_trees: dict[ifcopenshell.entity_instance, list[ifcopenshell.entity_instance]]¶
- elements: set[ifcopenshell.entity_instance]¶
- file¶
- has_additive_facet_in_current_list = False¶
- results: list[set[ifcopenshell.entity_instance]]¶
- class ifcopenshell.util.selector.FormatTransformer(element=None)¶
Bases:
lark.TransformerInitialize transformer with optional element for variable substitution
- ESCAPED_STRING(args)¶
- NUMBER(args)¶
- add(args)¶
Handle addition operation
- boolean(args)¶
- concat(args)¶
- divide(args)¶
Handle division operation
- expression(args)¶
- format_length(args)¶
- function(args)¶
- imperial_length(args)¶
- join(args)¶
- lower(args)¶
- metric_length(args)¶
- multiply(args)¶
Handle multiplication operation
- number(args)¶
- query_path(args)¶
Extract the query path from variable
- reverse(args)¶
- round(args)¶
- sort(args)¶
- start(args)¶
- substr(args)¶
- subtract(args)¶
Handle subtraction operation
- title(args)¶
- upper(args)¶
- variable(args)¶
Handle variable substitution like {{z}} or {{Pset_Wall.FireRating}}
- element = None¶
- 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)¶
- 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 – The IFC file object
query – Query to execute
elements – Base set of IFC elements for the query. If not provided, all elements in the IFC are queried. If provided, the query will be applied to this set of elements, so the result will be a subset of elements.
edit_in_place – If True, mutate the provided elements in place. Defaults to False
- Returns:
Set of filtered elements
Example:
# Select all the walls and slabs 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, element: ifcopenshell.entity_instance | None = None) str¶
Format a query string with optional element context for variable substitution.
- Parameters:
query – Format query string (can include {{variable}} placeholders)
element – Optional IFC element for variable substitution
- Returns:
Formatted string
- Example:
format(“{{z}} / 2”, element) # Substitutes element’s z value format(“imperial_length({{z}} / 2, 4)”, element) # Uses z in calculation
- 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 | dict[str, Any] | collections.abc.Iterable[ifcopenshell.entity_instance] | None, query: str | list[str], value: Any, *, concat: str = ', ') None¶
Set element value based on the provided query.
- Parameters:
element – IFC element to change.
query – String query to identify the attribute to change.
value – Value to set.
concat – Concatenation symbol, used only to deserialize property set enum values from string values.
- ifcopenshell.util.selector.filter_elements_grammar¶
- ifcopenshell.util.selector.format_grammar¶
- ifcopenshell.util.selector.get_element_grammar¶