Data validation module

Can be used to run validation on IFC file from the command line:

python -m ifcopenshell.validate /path/to/model.ifc --rules

Available flags:

  • --rules: Also check express rules.

  • --json: Produce JSON output.

  • --fields: Output more detailed information about failed entities (available only with --json).

Module Contents

exception ifcopenshell.validate.ValidationError(message, attribute=None)

Bases: Exception

Common base class for all non-exit exceptions.

Initialize self. See help(type(self)) for accurate signature.

class ifcopenshell.validate.json_logger
log(level, message, *args)
set_state(key, value)
ifcopenshell.validate.annotate_inst_attr_pos(inst: ifcopenshell.entity_instance, pos: int) str
ifcopenshell.validate.assert_valid(attr_type: attribute_types, val: Any, schema: schema_definition, no_throw=False, attr: attribute | None = None)
ifcopenshell.validate.assert_valid_inverse(attr: inverse_attribute, val: tuple[ifcopenshell.entity_instance], schema: schema_definition) bool
ifcopenshell.validate.format(val: Any) str
ifcopenshell.validate.get_entity_attributes(schema: schema_definition, entity: str) tuple[entity_type, tuple[attribute]]
ifcopenshell.validate.get_select_members(schema: schema_definition, ty: select_type) set[str]
ifcopenshell.validate.log_internal_cpp_errors(filename: str, logger: logging.Logger) None
ifcopenshell.validate.validate(f: ifcopenshell.file | str, logger: logging.Logger, express_rules=False) None

For an IFC population model f (or filepath to such a file) validate whether the entity attribute values are correctly supplied. As this is a function that is applied after a file has been parsed, certain types of errors in syntax, duplicate numeric identifiers or invalidate entity names are not caught by this function. Some of these might have been logged and can be retrieved by calling ifcopenshell.get_log(). A verification of the type, entity and global WHERE rules is also not implemented.

For every entity instance in the model, it is checked that the entity is not abstract that every attribute value is of the correct type and that the inverse attributes are of the correct cardinality.

Express simple types are checked for their valuation type. For select types it is asserted that the value conforms to one of the leaves. For enumerations it is checked that the value is indeed on of the items. For aggregations it is checked that the elements and the cardinality conforms. Type declarations (IfcInteger which is an integer) are unpacked until one of the above cases is reached.

It is recommended to supply the path to the file, so that internal C++ errors reported during the parse stage are also captured.


logger = ifcopenshell.validate.json_logger()
ifcopenshell.validate.validate("/path/to/model.ifc", logger, express_rules=True)
from pprint import pprint
ifcopenshell.validate.entity_attribute_map: dict[tuple[str, str], tuple[entity_type, tuple[attribute]]]
ifcopenshell.validate.select_members_cache: dict[tuple[str, str], set[str]]