From 77a497cdf7cc5bc0e6f6cec227d61cc10b87b045 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Thu, 4 Jan 2024 15:05:40 +0100 Subject: [PATCH] Generalize shortened file.schema attribute --- src/ifcopenshell-python/ifcopenshell/file.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/file.py b/src/ifcopenshell-python/ifcopenshell/file.py index 6b77a78b5e..7c34df54e2 100644 --- a/src/ifcopenshell-python/ifcopenshell/file.py +++ b/src/ifcopenshell-python/ifcopenshell/file.py @@ -358,7 +358,19 @@ class file(object): if attr[0:6] == "create": return functools.partial(self.create_entity, attr[6:]) elif attr == "schema": - return {"IFC4X3_ADD1": "IFC4X3"}.get(self.wrapped_data.schema, self.wrapped_data.schema) + prefixes = ("IFC", "X", "_ADD", "_TC") + reg = "".join(f"(?P<{s}>{s}\d+)?" for s in prefixes) + match = re.match(reg, self.wrapped_data.schema) + version_tuple = tuple( + map( + lambda pp: int(pp[1][len(pp[0]):]) if pp[1] else None, + ((p, match.group(p)) for p in prefixes), + ) + ) + return "".join( + "".join(map(str, t)) if t[1] else "" + for t in zip(prefixes, version_tuple[0:2]) + ) elif attr == "schema_identifier": return self.wrapped_data.schema elif attr == "schema_version":