Element Filter API¶
The element_filter module handles IFC file loading and element extraction.
Classes¶
IFCElementFilter¶
Object-oriented interface for filtering IFC elements.
from ifc_graph import IFCElementFilter
filter = IFCElementFilter(
file_path="model.ifc",
config={
'include_property_sets': True,
'include_materials': True,
'max_properties_per_element': 50,
}
)
# Load and extract
elements, ifc_file = filter.extract_elements(
element_types=['IfcWall', 'IfcDoor']
)
Filter and extract elements from IFC files.
This class provides a convenient interface for loading IFC files and extracting elements with their properties.
Source code in src/ifc_graph/element_filter.py
ifc_file
property
¶
Get the loaded IFC file, loading it if necessary.
__init__(file_path, config=None)
¶
Initialize the IFC element filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the IFC file |
required |
config
|
Optional[dict]
|
Optional extraction configuration |
None
|
Source code in src/ifc_graph/element_filter.py
extract_elements(element_types=None)
¶
Extract elements from the IFC file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element_types
|
Optional[list[str]]
|
List of IFC element types to extract |
None
|
Returns:
| Type | Description |
|---|---|
tuple[dict, file]
|
Tuple of (filtered_elements dictionary, ifc_file object) |
Source code in src/ifc_graph/element_filter.py
Exceptions¶
IFCLoadError¶
Raised when there's an error loading an IFC file.
from ifc_graph import IFCLoadError
try:
elements, ifc_file = filter_physical_elements("invalid.ifc")
except IFCLoadError as e:
print(f"Failed to load file: {e}")
IFCValidationError¶
Raised when an IFC file fails validation (doesn't exist, wrong extension, empty).
from ifc_graph import IFCValidationError
try:
elements, ifc_file = filter_physical_elements("missing.ifc")
except IFCValidationError as e:
print(f"Invalid file: {e}")
Functions¶
filter_physical_elements¶
The main function for extracting elements from IFC files.
from ifc_graph import filter_physical_elements
elements, ifc_file = filter_physical_elements(
ifc_file_path="model.ifc",
element_types=['IfcWall', 'IfcDoor', 'IfcWindow'],
config={
'include_property_sets': True,
'include_materials': True,
'max_properties_per_element': 50,
}
)
# elements is a dict: {'IfcWall': [...], 'IfcDoor': [...], ...}
# ifc_file is the loaded ifcopenshell.file object
Filters specific physical elements from an IFC file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ifc_file_path
|
str
|
Path to the IFC file |
required |
element_types
|
Optional[list[str]]
|
List of IFC element types to extract (e.g., ['IfcWall', 'IfcDoor']) |
None
|
config
|
Optional[dict]
|
Extraction configuration dictionary |
None
|
Returns:
| Type | Description |
|---|---|
tuple[dict, file]
|
Tuple of (filtered_elements dictionary, ifc_file object) |
Raises:
| Type | Description |
|---|---|
IFCLoadError
|
If the file cannot be loaded |
IFCValidationError
|
If the file is invalid |
Source code in src/ifc_graph/element_filter.py
load_ifc_file¶
Load an IFC file with validation and error handling.
from ifc_graph import load_ifc_file
ifc_file = load_ifc_file("model.ifc")
walls = ifc_file.by_type('IfcWall')
Load an IFC file with error handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the IFC file |
required |
Returns:
| Type | Description |
|---|---|
file
|
Loaded IFC file object |
Raises:
| Type | Description |
|---|---|
IFCLoadError
|
If there's an error loading the file |
Source code in src/ifc_graph/element_filter.py
validate_ifc_file¶
Validate that an IFC file exists and is accessible.
from ifc_graph.element_filter import validate_ifc_file, IFCValidationError
try:
validate_ifc_file("model.ifc")
print("File is valid")
except IFCValidationError as e:
print(f"Validation failed: {e}")
Validate that an IFC file exists and is accessible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the IFC file |
required |
Raises:
| Type | Description |
|---|---|
IFCValidationError
|
If the file is invalid or inaccessible |
Source code in src/ifc_graph/element_filter.py
extract_element_properties¶
Extract properties from a single IFC element for graph storage.
from ifc_graph import extract_element_properties, load_ifc_file
ifc_file = load_ifc_file("model.ifc")
element = ifc_file.by_type('IfcWall')[0]
props = extract_element_properties(element, config={})
# Returns: {'id': '123', 'name': 'Wall', 'guid': '...', 'type': 'IfcWall', ...}
Extract properties from an IFC element for graph storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
Any
|
IFC element to extract properties from |
required |
config
|
dict
|
Extraction configuration |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary of extracted properties |
Source code in src/ifc_graph/element_filter.py
extract_spatial_info¶
Extract spatial containment information for an element.
from ifc_graph import extract_spatial_info, load_ifc_file
ifc_file = load_ifc_file("model.ifc")
element = ifc_file.by_type('IfcWall')[0]
spatial = extract_spatial_info(element)
# Returns: [{'id': '456', 'name': 'Level 1', 'type': 'IfcBuildingStorey', ...}]
Extract spatial containment information for an element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
Any
|
IFC element to extract spatial info from |
required |
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of spatial structure information dictionaries |
Source code in src/ifc_graph/element_filter.py
extract_material_info¶
Extract material information for an element.
from ifc_graph import extract_material_info, load_ifc_file
ifc_file = load_ifc_file("model.ifc")
element = ifc_file.by_type('IfcWall')[0]
materials = extract_material_info(element)
# Returns: [{'element_id': '123', 'material_id': '789', 'material_name': 'Concrete', ...}]
Extract material information for an element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
Any
|
IFC element to extract material info from |
required |
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of material information dictionaries |
Source code in src/ifc_graph/element_filter.py
extract_property_sets¶
Extract property sets for an element.
from ifc_graph import extract_property_sets, load_ifc_file
ifc_file = load_ifc_file("model.ifc")
element = ifc_file.by_type('IfcWall')[0]
psets = extract_property_sets(element, max_properties=50)
# Returns: [{'element_id': '123', 'pset_name': 'Pset_WallCommon', 'properties': {...}}]
Extract property sets for an element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
Any
|
IFC element to extract property sets from |
required |
max_properties
|
int
|
Maximum number of properties to extract per element |
50
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of property set information dictionaries |
Source code in src/ifc_graph/element_filter.py
Configuration Options¶
The config parameter accepts a dictionary with these options:
| Option | Type | Default | Description |
|---|---|---|---|
include_property_sets |
bool | True |
Extract property sets |
include_materials |
bool | True |
Extract material info |
max_properties_per_element |
int | 50 |
Max properties to extract per element |
Example Configuration¶
config = {
'include_property_sets': True,
'include_materials': True,
'max_properties_per_element': 100,
}
elements, ifc_file = filter_physical_elements(
"model.ifc",
element_types=['IfcWall'],
config=config
)
Default Element Types¶
When element_types is not provided, these types are extracted:
IfcWallIfcDoorIfcWindowIfcStairIfcSlabIfcRoofIfcColumnIfcBeam
See Also¶
- Neo4j Store API - Database operations
- Python API Guide - Usage examples