ifcopenshell.util.selector

Module Contents

exception ifcopenshell.util.selector.SetElementValueException

Bases: Exception

Common 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

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)
parent(args)
prop(args)
property(args)
pset(args)
query(args)
type(args)
value(args)
container_parents
container_trees
file
results = []
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)
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 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 (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 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) 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 | Iterable[ifcopenshell.entity_instance] | None, query: str | list[str], value: Any) None
ifcopenshell.util.selector.filter_elements_grammar
ifcopenshell.util.selector.format_grammar
ifcopenshell.util.selector.get_element_grammar