Skip to content

Commit ccd8e77

Browse files
Devin-Crawfordpyansys-ci-botSamuelopez-ansys
authored
DOCS: Update documentation for Desktop.get_example (#6712)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Samuel Lopez <[email protected]>
1 parent b349dd4 commit ccd8e77

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update documentation for Desktop.get_example

src/ansys/aedt/core/application/design.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3701,7 +3701,7 @@ def copy_design_from(self, project, design, save_project=True, set_active_design
37013701
37023702
Parameters
37033703
----------
3704-
project : str
3704+
project : pathlib.Path or str
37053705
Full path and name for the project containing the design to copy.
37063706
The active design is maintained.
37073707
design : str
@@ -3906,7 +3906,7 @@ def save_project(self, file_name=None, overwrite=True, refresh_ids=False):
39063906
39073907
Parameters
39083908
----------
3909-
file_name : str, optional
3909+
file_name : str or pathlib.Path, optional
39103910
Full path and project name. The default is ````None``.
39113911
overwrite : bool, optional
39123912
Whether to overwrite the existing project. The default is ``True``.

src/ansys/aedt/core/desktop.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,12 +723,28 @@ def get_example(self, example_name, folder_name="."):
723723
example_name : str
724724
Name of the example for which the full path is desired.
725725
folder_name : str, optional
726-
Name of the example for which the full path is desired.
726+
Name of the subfolder in the ``"Examples"`` folder where the example having
727+
``example_name`` can be found. The default is ``"."`` which points to
728+
``self.install_path / "Examples"``
727729
728730
Returns
729731
-------
730-
str
731-
Return the full path and name of the example file if found, otherwise ``None``.
732+
pathlib.Path
733+
Return the path to the example file if found, otherwise ``None``.
734+
735+
Examples
736+
--------
737+
Create a copy of a built-in example.
738+
739+
>>> import shutil
740+
>>> from ansys.aedt.core import Desktop
741+
>>> from pathlib import Path
742+
>>> working_folder = Path("C:\") / "path" / "to" / "target_folder" # Windows
743+
>>> d = Desktop(version=252)
744+
>>> example_path = d.get_example("5G_SIW_Aperture_Antenna")
745+
>>> new_project = working_folder / example_path.name
746+
>>> working_folder.mkdir(parents=True, exist_ok=True)
747+
>>> shutil.copytree(example_path, new_project) # Copy example to new working folder.
732748
"""
733749
root = Path(self.install_path) / "Examples" / folder_name
734750

@@ -747,7 +763,7 @@ def get_example(self, example_name, folder_name="."):
747763
# Find the original Path object that matches the filename (case-insensitive)
748764
for file in all_files:
749765
if file.name.lower() == match_name:
750-
return str(file.resolve())
766+
return file.resolve()
751767

752768
@property
753769
def logger(self):

tests/system/general/test_01_Design.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,11 @@ def test_15b_copy_design_from(self, aedtapp, local_scratch):
217217
assert len(aedtapp.design_list) == 1
218218

219219
def test_15c_copy_example(self, aedtapp):
220-
example_name = aedtapp.desktop_class.get_example("5G_SIW_Aperture_Antenna")
220+
example_project = aedtapp.desktop_class.get_example("5G_SIW_Aperture_Antenna")
221221
from ansys.aedt.core.generic.file_utils import remove_project_lock
222222

223-
remove_project_lock(example_name)
224-
aedtapp.copy_design_from(example_name, "0_5G Aperture Element")
223+
remove_project_lock(example_project)
224+
aedtapp.copy_design_from(str(example_project), "0_5G Aperture Element")
225225
assert aedtapp.design_name == "0_5G Aperture Element"
226226
assert not aedtapp.desktop_class.get_example("fake")
227227

0 commit comments

Comments
 (0)