Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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 @@ -427,14 +427,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 @@ -445,19 +449,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 @@ -468,7 +476,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
4 changes: 4 additions & 0 deletions tests/_incompatible_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ backends:
# Export body facets added in 26.1
- tests/integration/test_design.py::test_write_body_facets_on_save[scdocx-None]
- tests/integration/test_design.py::test_write_body_facets_on_save[dsco-DISCO]
- tests/integration/test_design_export.py::test_export_to_disco_with_facets
# Edge tessellation added in 26.1
- tests/integration/test_tessellation.py::test_body_tessellate_with_edges

Expand Down Expand Up @@ -232,6 +233,7 @@ backends:
# Export body facets add in 26.1
- tests/integration/test_design.py::test_write_body_facets_on_save[scdocx-None]
- tests/integration/test_design.py::test_write_body_facets_on_save[dsco-DISCO]
- tests/integration/test_design_export.py::test_export_to_disco_with_facets
# Edge tessellation added in 26.1
- tests/integration/test_tessellation.py::test_body_tessellate_with_edges

Expand Down Expand Up @@ -315,6 +317,7 @@ backends:
# Export body facets add in 26.1
- tests/integration/test_design.py::test_write_body_facets_on_save[scdocx-None]
- tests/integration/test_design.py::test_write_body_facets_on_save[dsco-DISCO]
- tests/integration/test_design_export.py::test_export_to_disco_with_facets
# NURBS surface creation only available from 26.1 onwards
- tests/integration/test_design.py::test_nurbs_surface_body_creation
# Edge tessellation added in 26.1
Expand Down Expand Up @@ -355,6 +358,7 @@ backends:
# Export body facets add in 26.1
- tests/integration/test_design.py::test_write_body_facets_on_save[scdocx-None]
- tests/integration/test_design.py::test_write_body_facets_on_save[dsco-DISCO]
- tests/integration/test_design_export.py::test_export_to_disco_with_facets
# NURBS surface creation only available from 26.1 onwards
- tests/integration/test_design.py::test_nurbs_surface_body_creation
# Edge tessellation added in 26.1
Expand Down
7 changes: 4 additions & 3 deletions tests/integration/test_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,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 @@ -3807,7 +3807,7 @@ def test_vertices(modeler: Modeler, tmp_path_factory: pytest.TempPathFactory):
assert design.bodies[1].vertices[0].y.magnitude == pytest.approx(-0.00288675, 1e-6, 1e-6)
assert design.bodies[1].vertices[0].z.magnitude == pytest.approx(0.01, 1e-6, 1e-6)

print(design.bodies[1].vertices[0].id == "S,~sEbf61ff70-bc08-477a-8a5e-a7c7dc955f40.853__")
assert design.bodies[1].vertices[0].id == "S,~sEbf61ff70-bc08-477a-8a5e-a7c7dc955f40.853__"

assert design.bodies[0].vertices == []
assert design.bodies[1].vertices[1].position == pytest.approx(
Expand Down Expand Up @@ -3899,7 +3899,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(209996, 1e-3, 100)
assert file_location.exists()
design_read = modeler.open_file(file_location)
assert len(design_read.named_selections) == 5
Expand Down
32 changes: 31 additions & 1 deletion tests/integration/test_design_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,37 @@ 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)

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

# Check the exported file
assert file_location.exists()

# Import the dsco
design_read = modeler.open_file(file_location)

# Check the imported design
_checker_method(design_read, design, True)


def test_export_to_disco_with_facets(modeler: Modeler, tmp_path_factory: pytest.TempPathFactory):
"""Test exporting a design to dsco format with facets only available. in 261"""
"""This is a duplicate to ensure disco exporting is still covered before 261"""
skip_if_spaceclaim(modeler, test_export_to_disco.__name__, "disco export")
# Create a demo design
design = _create_demo_design(modeler)

# Define the location and expected file location
location = tmp_path_factory.mktemp("test_export_to_disco")
file_location = location / f"{design.name}.dsco"

# Export to dsco
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