diff --git a/src/ifcopenshell-python/ifcopenshell/validate.py b/src/ifcopenshell-python/ifcopenshell/validate.py index e3391add24..92e3681270 100644 --- a/src/ifcopenshell-python/ifcopenshell/validate.py +++ b/src/ifcopenshell-python/ifcopenshell/validate.py @@ -597,6 +597,25 @@ def validate_guid(guid: str) -> Union[str, None]: return "Couldn't decompress guid, it's not base64 encoded." return None +def to_string_header_entity(header_entity): + """Recreate IFC header string representation, like FILE_NAME(...)""" + def format_value(val): + if isinstance(val, str): + return f"'{val}'" + elif isinstance(val, tuple): + return "(" + ",".join(format_value(v) for v in val) + ")" + return str(val) + + # Prefer native .toString() if available (native IfcOpenShell wrapper) + if hasattr(header_entity, 'toString'): + return header_entity.toString() + + if hasattr(header_entity, '_fields'): + values = [format_value(getattr(header_entity, f)) for f in header_entity._fields] + else: + raise TypeError(f"Cannot stringify header_entity of type {type(header_entity)}") + + return f"{type(header_entity).__name__.upper()}({','.join(values)})" def validate_ifc_header(f: Union[ifcopenshell.file, ifcopenshell.simple_spf.file], logger: Logger) -> None: if type(f) is ifcopenshell.file: @@ -613,7 +632,7 @@ def validate_ifc_header(f: Union[ifcopenshell.file, ifcopenshell.simple_spf.file "Attribute '%s' has invalid type:\n" " Expected: %s\n Current value type: %s\n" ), - (s := header_entity.toString()), + (s := to_string_header_entity(header_entity)), annotate_inst_attr_pos(header_entity, index, s), name, expected_type,