Allow to write .ifcZIP | .ifcXML #2350

Transparently write any .ifc | .ifcXML | .ifcZIP formatted file
 with any extension :
- by guessing format from its extension
(eg. .zip | .ifczip | .ifcZIP | .ifcXML | .ifcxml | .IFC | .ifc)
zipped file can file can be of any supported format
- by specifying a format
- by specifying if it should be zipped
This commit is contained in:
CyrilWaechter
2022-11-26 05:19:01 +01:00
parent 8ec1b7bb3e
commit 25a7a95284
4 changed files with 137 additions and 10 deletions
@@ -38,6 +38,8 @@ import tempfile
import zipfile
from pathlib import Path
import ifcopenshell.util.file
if hasattr(os, "uname"):
platform_system = os.uname()[0].lower()
else:
@@ -83,14 +85,6 @@ class SchemaError(Error):
pass
def guess_format(path: Path) -> "str | None":
"""Try to guess format using file extension"""
if path.suffix.lower() in (".ifczip", ".zip"):
return ".ifcZIP"
if path.suffix.lower() in (".ifcxml", ".xml"):
return ".ifcXML"
def open(path: "os.PathLike | str", format: str = None) -> file:
"""Loads an IFC dataset from a filepath
@@ -104,7 +98,7 @@ def open(path: "os.PathLike | str", format: str = None) -> file:
"""
path = Path(path)
if format is None:
format = guess_format(path)
format = ifcopenshell.util.file.guess_format(path)
if format == ".ifcXML":
f = ifcopenshell_wrapper.parse_ifcxml(str(path.absolute()))
if f: