Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/2231.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add option to write body facets to explicit export methods
16 changes: 12 additions & 4 deletions src/ansys/geometry/core/designer/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,18 @@ def __build_export_file_location(self, location: Path | str | None, ext: str) ->
"""
return (Path(location) if location else Path.cwd()) / f"{self.name}.{ext}"

def export_to_scdocx(self, location: Path | str | None = None) -> Path:
def export_to_scdocx(
self, location: Path | str | None = None, write_body_facets: bool = False
) -> Path:
"""Export the design to an scdocx file.

Parameters
----------
location : ~pathlib.Path | str, optional
Location on disk to save the file to. If None, the file will be saved
in the current working directory.
write_body_facets : bool, default: False
Option to write body facets into the saved file. SCDOCX and DISCO only, 26R1 and later.

Returns
-------
Expand All @@ -444,19 +448,23 @@ def export_to_scdocx(self, location: Path | str | None = None) -> Path:
file_location = self.__build_export_file_location(location, "scdocx")

# Export the design to an scdocx file
self.download(file_location, DesignFileFormat.SCDOCX)
self.download(file_location, DesignFileFormat.SCDOCX, write_body_facets)

# Return the file location
return file_location

def export_to_disco(self, location: Path | str | None = None) -> Path:
def export_to_disco(
self, location: Path | str | None = None, write_body_facets: bool = False
) -> Path:
"""Export the design to an dsco file.

Parameters
----------
location : ~pathlib.Path | str, optional
Location on disk to save the file to. If None, the file will be saved
in the current working directory.
write_body_facets : bool, default: False
Option to write body facets into the saved file. SCDOCX and DISCO only, 26R1 and later.

Returns
-------
Expand All @@ -467,7 +475,7 @@ def export_to_disco(self, location: Path | str | None = None) -> Path:
file_location = self.__build_export_file_location(location, "dsco")

# Export the design to an dsco file
self.download(file_location, DesignFileFormat.DISCO)
self.download(file_location, DesignFileFormat.DISCO, write_body_facets)

# Return the file location
return file_location
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/test_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ def test_download_file(modeler: Modeler, tmp_path_factory: pytest.TempPathFactor
else:
file_save = tmp_path_factory.mktemp("scdoc_files_save") / "cylinder.scdocx"

design.save(file_location=file_save)
design.save(file_location=file_save, write_body_facets=True)

# Check for other exports - Windows backend...
if not BackendType.is_core_service(modeler.client.backend_type):
Expand Down Expand Up @@ -3778,7 +3778,8 @@ def test_vertices(modeler: Modeler, tmp_path_factory: pytest.TempPathFactory):

location = tmp_path_factory.mktemp("test_export_to_scdocx")
file_location = location / f"{design.name}.scdocx"
design.export_to_scdocx(location)
exported_file = design.export_to_scdocx(location, write_body_facets=True)
assert exported_file.stat().st_size == pytest.approx(216642, 1e-3, 100)
assert file_location.exists()
design_read = modeler.open_file(file_location)
assert len(design_read.named_selections) == 5
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/test_design_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ def test_export_to_disco(modeler: Modeler, tmp_path_factory: pytest.TempPathFact
file_location = location / f"{design.name}.dsco"

# Export to dsco
design.export_to_disco(location)
exported_file = design.export_to_disco(location, write_body_facets=True)

# Checking file size to ensure facets are exported
assert exported_file.stat().st_size == pytest.approx(53844, 1e-3, 100)

# Check the exported file
assert file_location.exists()
Expand Down
Loading