diff --git a/src/ifcopenshell-python/ifcopenshell/file.py b/src/ifcopenshell-python/ifcopenshell/file.py index 8713dd4f66..9baaeac465 100644 --- a/src/ifcopenshell-python/ifcopenshell/file.py +++ b/src/ifcopenshell-python/ifcopenshell/file.py @@ -893,12 +893,22 @@ class file_mixin: unzipped_path.unlink() return - @staticmethod - def from_string(s: str) -> file: - return file(ifcopenshell_wrapper.read(s)) - def to_string(self) -> str: return self.to_string() + + @staticmethod + def _determine_schema_identifier( + schema: Optional[ifcopenshell.util.schema.IFC_SCHEMA] = None, + schema_version: Optional[tuple[int, int, int, int]] = None, + ): + if schema_version: + prefixes = ("IFC", "X", "_ADD", "_TC") + schema = "".join("".join(map(str, t)) if t[1] else "" for t in zip(prefixes, schema_version)) + elif schema: + schema = {"IFC4X3": "IFC4X3_ADD2"}.get(schema, schema) + else: + schema = "IFC4" + return schema @property def storage(self) -> Optional[rocksdb_file_storage]: diff --git a/src/ifcwrap/IfcParseWrapper.i b/src/ifcwrap/IfcParseWrapper.i index d66561853a..2fbc43b079 100644 --- a/src/ifcwrap/IfcParseWrapper.i +++ b/src/ifcwrap/IfcParseWrapper.i @@ -326,13 +326,17 @@ private: } %pythoncode %{ + @staticmethod + def from_string(s: str) -> 'file': + return read(s) + schema = property(schema_name) header = property(header) _registry = {} _old_init = __init__ def __init__(self, schema=None, schema_version=None): - self._old_init(*filter(None, (schema, schema_version))) + self._old_init(self._determine_schema_identifier(schema=schema, schema_version=schema_version)) def __setattr__(self, k, v): object.__setattr__(self, k, v)