Skip to content

Commit 05ac9d5

Browse files
Alberto-DMpre-commit-ci[bot]pyansys-ci-bot
authored
FIX: Solved issue #6801, improved desktop.save_project() (#6847)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 0142f00 commit 05ac9d5

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

doc/changelog.d/6847.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Solved issue #6801, improved desktop.save_project()

src/ansys/aedt/core/desktop.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,9 +1006,9 @@ def save_project(self, project_name=None, project_path=None):
10061006
project_name : str, optional
10071007
Project name. The default is ``None``, in which case the active project
10081008
is used.
1009-
project_path : str, optional
1010-
Full path to the project. The default is ``None``. If a path is
1011-
provided, ``save as`` is used.
1009+
project_path : str, Path, optional
1010+
Full path to the project. The default is ``None``, in which case the current project is saved.
1011+
If a path is provided, "save as" is used.
10121012
10131013
Returns
10141014
-------
@@ -1017,10 +1017,17 @@ def save_project(self, project_name=None, project_path=None):
10171017
"""
10181018
if not project_name:
10191019
oproject = self.odesktop.GetActiveProject()
1020+
project_name = oproject.GetName()
10201021
else:
10211022
oproject = self.odesktop.SetActiveProject(project_name)
10221023
if project_path:
1023-
oproject.SaveAs(project_path, True)
1024+
project_path = Path(project_path)
1025+
# check if the path ends with a file (by verifying if it has an extension)
1026+
if project_path.suffix:
1027+
final_path = project_path
1028+
else:
1029+
final_path = project_path / (project_name + ".aedt")
1030+
oproject.SaveAs(str(final_path), True)
10241031
else:
10251032
oproject.Save()
10261033
return True
@@ -1691,7 +1698,7 @@ def submit_job(
16911698
project_path = Path(project_file).parent
16921699
project_name = Path(project_file).stem
16931700
if project_name in self.project_list:
1694-
self.save_project(project_path, project_path)
1701+
self.save_project(project_name, project_path)
16951702
if not aedt_full_exe_path:
16961703
version = self.odesktop.GetVersion()[2:6]
16971704
if version >= "22.2":
@@ -1812,8 +1819,7 @@ def submit_ansys_cloud_job(
18121819
project_path = Path(project_file).parent
18131820
project_name = Path(project_file).stem
18141821
if project_name in self.project_list:
1815-
self.save_project(project_path, project_path)
1816-
1822+
self.save_project(project_name, project_path)
18171823
if not job_name:
18181824
job_name = generate_unique_name(project_name)
18191825
if project_name in self.project_list:

tests/system/general/test_01_Design.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# SOFTWARE.
2424

2525
import os
26+
from pathlib import Path
2627
import tempfile
2728

2829
import pytest
@@ -519,6 +520,35 @@ def test_42_save_project_with_file_name(self, aedtapp, local_scratch):
519520
aedtapp.save_project(file_name=new_project)
520521
assert os.path.isfile(new_project)
521522

523+
aedtapp.close_project(aedtapp.project_name)
524+
525+
def test_desktop_save_as(self, aedtapp, local_scratch):
526+
# Save as passing a string
527+
aedtapp.create_new_project("test_desktop_save_as")
528+
new_project = os.path.join(local_scratch.path, "new.aedt")
529+
assert os.path.exists(local_scratch.path)
530+
assert aedtapp.desktop_class.save_project(project_path=new_project)
531+
assert os.path.isfile(new_project)
532+
533+
# Test using Path instead of string
534+
new_project_path = Path(local_scratch.path) / "new_2.aedt"
535+
assert aedtapp.desktop_class.save_project(project_path=new_project_path)
536+
assert new_project_path.exists()
537+
538+
# Test using Path with only dir
539+
only_project_path = Path(local_scratch.path)
540+
assert aedtapp.desktop_class.save_project(project_path=only_project_path)
541+
assert new_project_path.exists()
542+
543+
# Test using Path and providing a project name
544+
new_project_path = Path(local_scratch.path) / "new_3.aedt"
545+
project_name = aedtapp.project_name
546+
assert aedtapp.desktop_class.save_project(project_name=project_name, project_path=new_project_path)
547+
assert new_project_path.exists()
548+
549+
aedtapp.close_project(aedtapp.project_name)
550+
522551
def test_43_edit_notes(self, aedtapp):
552+
aedtapp.create_new_project("Test_notes")
523553
assert aedtapp.edit_notes("this a test")
524554
assert not aedtapp.edit_notes(1)

0 commit comments

Comments
 (0)