Skip to content

Commit 16f592e

Browse files
maxcapodi78maxcapodi78
authored andcommitted
Merge branch 'main' into release/0.4
2 parents 4b54cdb + 773afcb commit 16f592e

File tree

6 files changed

+43
-37
lines changed

6 files changed

+43
-37
lines changed

_unittest/test_01_Design.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def test_14_get_nominal_variation(self):
130130
assert self.aedtapp.get_nominal_variation() != [] or self.aedtapp.get_nominal_variation() is not None
131131

132132
def test_15a_duplicate_design(self):
133+
self.aedtapp.duplicate_design("non_valid1", False)
133134
self.aedtapp.duplicate_design("myduplicateddesign")
134135
assert "myduplicateddesign" in self.aedtapp.design_list
135136
self.aedtapp.delete_design("myduplicateddesign", "NewDesign")
@@ -266,6 +267,7 @@ def test_29_change_registry_key(self):
266267
assert not desktop.change_registry_key("test_key", 2.0)
267268

268269
def test_30_object_oriented(self):
270+
self.aedtapp["my_oo_variable"] = "15mm"
269271
# self.aedtapp.set_active_design("myname")
270272
assert self.aedtapp.get_oo_name(self.aedtapp.oproject, "Variables")
271273
assert self.aedtapp.get_oo_name(self.aedtapp.odesign, "Variables")

_unittest/test_07_Object3D.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ def test_24_filter_faces_by_area(self):
434434
if faces_greater_equal:
435435
for face_object in faces_greater_equal:
436436
for face in face_object:
437-
assert (face.area - 100) >= 1e-12
437+
assert (face.area - 100) >= -1e-12
438438

439439
faces_smaller_equal = []
440440
for obj in self.aedtapp.modeler.object_list:
@@ -447,21 +447,21 @@ def test_24_filter_faces_by_area(self):
447447

448448
faces_greater = []
449449
for obj in self.aedtapp.modeler.object_list:
450-
if obj.faces_by_area(100):
451-
faces_greater.append(obj.faces_by_area(100, ">"))
450+
if obj.faces_by_area(99):
451+
faces_greater.append(obj.faces_by_area(99, ">"))
452452
if faces_greater:
453453
for face_object in faces_greater:
454454
for face in face_object:
455-
assert (face.area - 100) > 1e-12
455+
assert (face.area - 99) > 0
456456

457457
faces_smaller = []
458458
for obj in self.aedtapp.modeler.object_list:
459-
if obj.faces_by_area(100):
460-
faces_smaller.append(obj.faces_by_area(100, "<"))
459+
if obj.faces_by_area(105):
460+
faces_smaller.append(obj.faces_by_area(105, "<"))
461461
if faces_smaller:
462462
for face_object in faces_smaller:
463463
for face in face_object:
464-
assert (face.area - 100) < 1e-12
464+
assert (face.area - 105) < 0
465465

466466
if not is_ironpython:
467467
with pytest.raises(ValueError):

pyaedt/application/Design.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2922,7 +2922,7 @@ def copy_design_from(self, project_fullname, design_name):
29222922
return new_designname
29232923

29242924
@pyaedt_function_handler()
2925-
def duplicate_design(self, label):
2925+
def duplicate_design(self, label, save_after_duplicate=True):
29262926
"""Copy a design to a new name.
29272927
29282928
The new name consists of the original
@@ -2933,6 +2933,9 @@ def duplicate_design(self, label):
29332933
----------
29342934
label : str
29352935
Name of the design to copy.
2936+
save_after_duplicate : bool, optional
2937+
Save project after the duplication is completed. If ``False``, pyaedt objects like boundaries will not be
2938+
available.
29362939
29372940
Returns
29382941
-------
@@ -2960,6 +2963,9 @@ def duplicate_design(self, label):
29602963
self.design_name = newname
29612964
self._close_edb()
29622965
AedtObjects.__init__(self, is_inherithed=True)
2966+
if save_after_duplicate:
2967+
self.oproject.Save()
2968+
self._project_dictionary = None
29632969
return True
29642970

29652971
@pyaedt_function_handler()

pyaedt/desktop.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ def __init__(
342342
self._main.isoutsideDesktop = True
343343
self.release_on_exit = True
344344
self.logfile = None
345+
self._logger = aedt_logger.AedtLogger(filename=self.logfile, level=logging.DEBUG)
346+
self._logger.info("Logger Started")
347+
self._main.aedt_logger = self._logger
345348
if "oDesktop" in dir(): # pragma: no cover
346349
self.release_on_exit = False
347350
self._main.oDesktop = oDesktop
@@ -361,11 +364,11 @@ def __init__(
361364
del self._main.oDesktop
362365
self._main.student_version, version_key, version = self._set_version(specified_version, student_version)
363366
if _com == "ironpython": # pragma: no cover
364-
print("Launching PyAEDT outside AEDT with IronPython.")
367+
self._logger.info("Launching PyAEDT outside AEDT with IronPython.")
365368
self._init_ironpython(non_graphical, new_desktop_session, version)
366369
elif _com == "pythonnet_v3":
367370
if version_key < "2022.2" or not settings.use_grpc_api:
368-
print("Launching PyAEDT outside Electronics Desktop with CPython and Pythonnet")
371+
self._logger.info("Launching PyAEDT outside Electronics Desktop with CPython and Pythonnet")
369372
self._init_cpython(
370373
non_graphical,
371374
new_desktop_session,
@@ -376,9 +379,6 @@ def __init__(
376379
)
377380
else:
378381
self._init_cpython_new(non_graphical, new_desktop_session, version, self._main.student_version)
379-
# print("Launching PyAEDT outside AEDT with CPython and Pythonnet.")
380-
# self._init_cpython(non_graphical, new_desktop_session, version,
381-
# self._main.student_version, version_key)
382382
else:
383383
oAnsoftApp = win32com.client.Dispatch(version)
384384
self._main.oDesktop = oAnsoftApp.GetAppDesktop()
@@ -465,11 +465,11 @@ def current_version_student(self):
465465
def _init_desktop(self):
466466
self._main.AEDTVersion = self._main.oDesktop.GetVersion()[0:6]
467467
self._main.oDesktop.RestoreWindow()
468-
self._logger = aedt_logger.AedtLogger(filename=self.logfile, level=logging.DEBUG)
469-
self._logger.info("Logger Started on %s", self.logfile)
470-
self._main.aedt_logger = self._logger
471468
self._main.sDesktopinstallDirectory = self._main.oDesktop.GetExeDir()
472469
self._main.pyaedt_initialized = True
470+
self._logger = aedt_logger.AedtLogger(filename=self.logfile, level=logging.DEBUG)
471+
self._logger.info("Logger file %s in use.")
472+
self._main.aedt_logger = self._logger
473473

474474
def _set_version(self, specified_version, student_version):
475475
student_version_flag = False
@@ -569,14 +569,13 @@ def _init_cpython(
569569
sys.path.append(base_path)
570570
sys.path.append(os.path.join(base_path, "PythonFiles", "DesktopPlugin"))
571571
launch_msg = "AEDT installation Path {}.".format(base_path)
572-
print(launch_msg)
573-
print("===================================================================================")
572+
self.logger.info(launch_msg)
574573
clr.AddReference("Ansys.Ansoft.CoreCOMScripting")
575574
AnsoftCOMUtil = __import__("Ansys.Ansoft.CoreCOMScripting")
576575
self.COMUtil = AnsoftCOMUtil.Ansoft.CoreCOMScripting.Util.COMUtil
577576
self._main.COMUtil = self.COMUtil
578577
StandalonePyScriptWrapper = AnsoftCOMUtil.Ansoft.CoreCOMScripting.COM.StandalonePyScriptWrapper
579-
print("pyaedt info: Launching AEDT with module Pythonnet.")
578+
self.logger.info("Launching AEDT with module Pythonnet.")
580579
processID = []
581580
if IsWindows:
582581
processID = self._get_tasks_list_windows(student_version)
@@ -603,9 +602,9 @@ def _init_cpython(
603602
self._dispatch_win32(version)
604603
elif version_key >= "2021.2":
605604
if student_version:
606-
print("pyaedt info: {} Student version started with process ID {}.".format(version, proc[0]))
605+
self.logger.info("{} Student version started with process ID {}.".format(version, proc[0]))
607606
else:
608-
print("pyaedt info: {} Started with process ID {}.".format(version, proc[0]))
607+
self.logger.info("{} Started with process ID {}.".format(version, proc[0]))
609608
context = pythoncom.CreateBindCtx(0)
610609
running_coms = pythoncom.GetRunningObjectTable()
611610
monikiers = running_coms.EnumRunning()
@@ -617,7 +616,7 @@ def _init_cpython(
617616
self._main.oDesktop = win32com.client.Dispatch(obj.QueryInterface(pythoncom.IID_IDispatch))
618617
break
619618
else:
620-
warnings.warn(
619+
self.logger.warning(
621620
"PyAEDT is not supported in AEDT versions older than 2021.2. Trying to launch PyAEDT with PyWin32."
622621
)
623622
self._dispatch_win32(version)
@@ -629,9 +628,8 @@ def _init_cpython_new(self, non_graphical, new_aedt_session, version, student_ve
629628
import ScriptEnv
630629

631630
launch_msg = "AEDT installation Path {}".format(base_path)
632-
print(launch_msg)
633-
print("===================================================================================")
634-
print("pyaedt info: Launching AEDT with PyDesktopPlugin.")
631+
self.logger.info(launch_msg)
632+
self.logger.info("Launching AEDT with PyDesktopPlugin.")
635633
if new_aedt_session or not self.port:
636634
self.port = _find_free_port()
637635
self.machine = ""
@@ -662,12 +660,12 @@ def _init_cpython_new(self, non_graphical, new_aedt_session, version, student_ve
662660
if non_graphical:
663661
settings.enable_desktop_logs = False
664662
if student_version:
665-
print("pyaedt info: {} Student version started with process ID {}.".format(version, _proc))
663+
self.logger.info("{} Student version started with process ID {}.".format(version, _proc))
666664
else:
667-
print("pyaedt info: {} Started with process ID {}.".format(version, _proc))
665+
self.logger.info("{} Started with process ID {}.".format(version, _proc))
668666

669667
else:
670-
warnings.warn("PyDesktopPlugin is not supported in AEDT versions older than 2022.2.")
668+
self.logger.warning("PyDesktopPlugin is not supported in AEDT versions older than 2022.2.")
671669

672670
def _set_logger_file(self):
673671
# Set up the log file in the AEDT project directory

pyaedt/modeler/Object3d.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,20 +2624,20 @@ def faces_by_area(self, area, area_filter="==", tolerance=1e-12):
26242624

26252625
faces = []
26262626
for face in self.faces:
2627-
if area_filter is "==":
2627+
if area_filter == "==":
26282628
if abs(face.area - area) < tolerance:
26292629
faces.append(face)
2630-
if area_filter is ">=":
2631-
if (face.area - area) >= tolerance:
2630+
if area_filter == ">=":
2631+
if (face.area - area) >= -tolerance:
26322632
faces.append(face)
2633-
if area_filter is "<=":
2633+
if area_filter == "<=":
26342634
if (face.area - area) <= tolerance:
26352635
faces.append(face)
2636-
if area_filter is ">":
2637-
if (face.area - area) > tolerance:
2636+
if area_filter == ">":
2637+
if (face.area - area) > 0:
26382638
faces.append(face)
2639-
if area_filter is "<":
2640-
if (face.area - area) < tolerance:
2639+
if area_filter == "<":
2640+
if (face.area - area) < 0:
26412641
faces.append(face)
26422642

26432643
return faces

pyaedt/modules/Boundary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ def update(self):
590590
self._app.oboundary.SetSBRTxRxSettings(self._get_args()) # pragma: no cover
591591
elif self.type == "Floquet Port":
592592
self._app.oboundary.EditFloquetPort(self._boundary_name, self._get_args()) # pragma: no cover
593-
elif self.type == "EndConnection":
593+
elif self.type == "End Connection":
594594
self._app.oboundary.EditEndConnection(self._boundary_name, self._get_args())
595595
else:
596596
return False # pragma: no cover

0 commit comments

Comments
 (0)