Skip to content

Commit 8ae564c

Browse files
Devin-CrawfordSamuelopez-ansyspyansys-ci-botSMoraisAnsys
authored
FIX: Copy Design #5623 (#5993)
Co-authored-by: Samuelopez-ansys <samuel.lopez@ansys.com> Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Co-authored-by: Samuel Lopez <85613111+Samuelopez-ansys@users.noreply.github.com> Co-authored-by: Sébastien Morais <146729917+SMoraisAnsys@users.noreply.github.com>
1 parent a8ec659 commit 8ae564c

4 files changed

Lines changed: 45 additions & 1 deletion

File tree

doc/changelog.d/5993.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Copy Design #5623

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3639,7 +3639,7 @@ def copy_design_from(self, project, design, save_project=True, set_active_design
36393639
if set_active_design:
36403640
self._close_edb()
36413641
self._init_design(project_name=self.project_name, design_name=new_designname)
3642-
self.set_active_design(active_design)
3642+
self.set_active_design(new_designname)
36433643
# return the pasted design name
36443644
return new_designname
36453645

src/ansys/aedt/core/desktop.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import atexit
3333
import datetime
34+
from difflib import get_close_matches
3435
import gc
3536
import os
3637
from pathlib import Path
@@ -692,6 +693,42 @@ def install_path(self):
692693
except Exception: # pragma: no cover
693694
return self.installed_versions[version_key + "CL"]
694695

696+
@pyaedt_function_handler()
697+
def get_example(self, example_name, folder_name="."):
698+
"""Retrieve the path to a built-in example project.
699+
700+
Parameters
701+
----------
702+
example_name : str
703+
Name of the example for which the full path is desired.
704+
folder_name : str, optional
705+
Name of the example for which the full path is desired.
706+
707+
Returns
708+
-------
709+
str
710+
Return the full path and name of the example file if found, otherwise ``None``.
711+
"""
712+
713+
root = Path(self.install_path) / "Examples" / folder_name
714+
715+
# Gather all files
716+
all_files = [f for f in root.rglob("*") if f.is_file() and not f.suffix.lower() == ".pdf"]
717+
718+
# Normalize names for fuzzy matching
719+
filenames = [f.name.lower() for f in all_files]
720+
name_lower = example_name.lower()
721+
722+
# Get close matches
723+
close = get_close_matches(name_lower, filenames, n=1, cutoff=0.6)
724+
725+
if close:
726+
match_name = close[0]
727+
# Find the original Path object that matches the filename (case-insensitive)
728+
for file in all_files:
729+
if file.name.lower() == match_name:
730+
return str(file.resolve())
731+
695732
@property
696733
def logger(self):
697734
"""AEDT logger."""

tests/system/general/test_01_Design.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ def test_15b_copy_design_from(self):
206206
new_design = self.aedtapp.copy_design_from(origin, "myduplicateddesign")
207207
assert new_design in self.aedtapp.design_list
208208

209+
def test_15c_copy_example(self):
210+
example_name = self.aedtapp.desktop_class.get_example("5G_SIW_Aperture_Antenna")
211+
self.aedtapp.copy_design_from(example_name, "0_5G Aperture Element")
212+
assert self.aedtapp.design_name == "0_5G Aperture Element"
213+
assert not self.aedtapp.desktop_class.get_example("fake")
214+
209215
def test_16_renamedesign(self, add_app, test_project_file):
210216
prj_file = test_project_file(test_project_name)
211217
self.aedtapp.load_project(file_name=prj_file, design="myname", close_active=True)

0 commit comments

Comments
 (0)