ifcopenshell.validate

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.

attribute
class ifcopenshell.validate.LogDetectionHandler(level=NOTSET)

Bases: logging.Handler

Handler instances dispatch logging events to specific destinations.

The base handler class. Acts as a placeholder which defines the Handler interface. Handlers can optionally use Formatter instances to format records as desired. By default, no formatter is specified; in this case, the ‘raw’ message as determined by record.message is logged.

Initializes the instance - basically setting the formatter to None and the filter list to empty.

emit(record)

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

message_logged = False
class ifcopenshell.validate.json_logger
log(level, message, *args)
set_state(key, value)
state
statements = []
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(f: ifcopenshell.file, 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.

Example:

logger = ifcopenshell.validate.json_logger()
ifcopenshell.validate.validate("/path/to/model.ifc", logger, express_rules=True)
from pprint import pprint
pprint(logger.statements)
ifcopenshell.validate.aggregation_type
ifcopenshell.validate.attribute
ifcopenshell.validate.attribute_types
ifcopenshell.validate.entity_attribute_map: dict[tuple[str, str], tuple[entity_type, tuple[attribute]]]
ifcopenshell.validate.entity_type
ifcopenshell.validate.enumeration_type
ifcopenshell.validate.filenames
ifcopenshell.validate.inverse_attribute
ifcopenshell.validate.log_entry_type
ifcopenshell.validate.named_type
ifcopenshell.validate.schema_definition
ifcopenshell.validate.select_members_cache: dict[tuple[str, str], set[str]]
ifcopenshell.validate.select_type
ifcopenshell.validate.simple_type
ifcopenshell.validate.simple_type_python_mapping
ifcopenshell.validate.type_declaration