MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / write

Method write

src/ifcopenshell-python/ifcopenshell/file.py:1004–1041  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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:

Callers 15

test_opening_unicodeFunction · 0.45
create_caseFunction · 0.45
generate_03.pyFile · 0.45
generate_23.pyFile · 0.45
generate_06.pyFile · 0.45
generate_18.pyFile · 0.45
generate_11.pyFile · 0.45
generate_12.pyFile · 0.45
generate_05.pyFile · 0.45
generate_16.pyFile · 0.45
generate_21.pyFile · 0.45

Calls 1

unlinkMethod · 0.45

Tested by 5

test_opening_unicodeFunction · 0.36
create_caseFunction · 0.36
get_ifc_filepathMethod · 0.36
test_ifc_zipMethod · 0.36