Write ifc model to file. :param format: Force use of a specific format. Guessed from file name if None. Supported formats : .ifc, .ifcZIP (equivalent to format=".ifc" with zipped=True) :param zipped: zip the file after it is written Example:
(self, path: os.PathLike | str, format: Optional[str] = None, zipped: bool = False)
| 1002 | pass # Header is invalid |
| 1003 | |
| 1004 | def write(self, path: os.PathLike | str, format: Optional[str] = None, zipped: bool = False) -> None: |
| 1005 | """Write ifc model to file. |
| 1006 | |
| 1007 | :param format: Force use of a specific format. Guessed from file name |
| 1008 | if None. Supported formats : .ifc, .ifcZIP (equivalent to |
| 1009 | format=".ifc" with zipped=True) |
| 1010 | :param zipped: zip the file after it is written |
| 1011 | |
| 1012 | Example: |
| 1013 | |
| 1014 | .. code:: python |
| 1015 | |
| 1016 | model.write("path/to/model.ifc") |
| 1017 | model.write("path/to/model.ifcZIP") |
| 1018 | model.write("path/to/model.anyextension", format=".ifc") |
| 1019 | """ |
| 1020 | path = Path(path) |
| 1021 | path.parent.mkdir(parents=True, exist_ok=True) |
| 1022 | |
| 1023 | if format == None: |
| 1024 | format = ifcopenshell.guess_format(path) |
| 1025 | if format == ".ifcXML": |
| 1026 | raise NotImplementedError("Writing .ifcXML files is not supported") |
| 1027 | if format == ".ifcZIP": |
| 1028 | return self.write(path, ".ifc", zipped=True) |
| 1029 | self.wrapped_data.write(str(path)) |
| 1030 | |
| 1031 | if zipped: |
| 1032 | unzipped_path = path.with_suffix(format) |
| 1033 | path.rename(unzipped_path) |
| 1034 | with zipfile.ZipFile(path, "w") as zip_file: |
| 1035 | zip_file.write( |
| 1036 | unzipped_path, |
| 1037 | unzipped_path.name, |
| 1038 | compress_type=zipfile.ZIP_DEFLATED, |
| 1039 | ) |
| 1040 | unzipped_path.unlink() |
| 1041 | return |
| 1042 | |
| 1043 | @staticmethod |
| 1044 | def from_string(s: str) -> file: |