Skip to content

Commit 379d265

Browse files
FIX: Allow Object3d to be used in create_current_source_from_objects (#6804)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent c5e8187 commit 379d265

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

doc/changelog.d/6804.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow Object3d to be used in create_current_source_from_objects

src/ansys/aedt/core/modeler/cad/primitives.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ def model_consistency_report(self):
842842
return report
843843

844844
@property
845-
def objects_by_name(self):
845+
def objects_by_name(self) -> dict[str, Object3d]:
846846
"""Object dictionary organized by name.
847847
848848
Returns
@@ -6587,26 +6587,26 @@ def value_in_object_units(self, value):
65876587
return numeric_list
65886588

65896589
@pyaedt_function_handler(obj_to_check="assignment")
6590-
def does_object_exists(self, assignment):
6590+
def does_object_exists(self, assignment) -> bool:
65916591
"""Check to see if an object exists.
65926592
65936593
Parameters
65946594
----------
6595-
assignment : str, int
6596-
Object name or object ID.
6595+
assignment : str, int or :class:`ansys.aedt.core.modeler.cad.object_3d.Object3d`
6596+
Object name or object ID or Object3d to check.
65976597
65986598
Returns
65996599
-------
66006600
bool
66016601
``True`` when successful, ``False`` when failed.
6602-
66036602
"""
6604-
if isinstance(assignment, int) and assignment in self.objects:
6605-
return True
6606-
elif assignment in self.objects_by_name:
6607-
return True
6608-
else:
6609-
return False
6603+
if isinstance(assignment, int):
6604+
return assignment in self.objects
6605+
elif isinstance(assignment, str):
6606+
return assignment in self.objects_by_name
6607+
elif isinstance(assignment, Object3d):
6608+
return assignment.name in self.objects_by_name
6609+
return False
66106610

66116611
@pyaedt_function_handler(parts="assignment", region_name="name")
66126612
def create_subregion(self, padding_values, padding_types, assignment, name=None):

src/ansys/aedt/core/modeler/cad/primitives_3d.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from math import tan
3636
import os
3737
from pathlib import Path
38+
from typing import TYPE_CHECKING
3839

3940
from ansys.aedt.core import Edb
4041
from ansys.aedt.core.base import PyAedtBase
@@ -53,6 +54,9 @@
5354
from ansys.aedt.core.modeler.cad.primitives import GeometryModeler
5455
from ansys.aedt.core.modeler.geometry_operators import GeometryOperators
5556

57+
if TYPE_CHECKING:
58+
from ansys.aedt.core.modeler.cad.object_3d import Object3d
59+
5660

5761
class Primitives3D(GeometryModeler, PyAedtBase):
5862
"""Manages primitives in applications using the 3D modeler.
@@ -111,7 +115,7 @@ def __init__(self, application):
111115
self.multiparts = []
112116

113117
@pyaedt_function_handler(position="origin", dimensions_list="sizes", matname="material")
114-
def create_box(self, origin, sizes, name=None, material=None, **kwargs):
118+
def create_box(self, origin, sizes, name=None, material=None, **kwargs) -> "Object3d":
115119
"""Create a box.
116120
117121
Parameters

tests/system/general/test_20_HFSS.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,13 +787,24 @@ def test_17B_update_assignment(self):
787787

788788
def test_18_create_sources_on_objects(self):
789789
box1 = self.aedtapp.modeler.create_box([30, 0, 0], [40, 10, 5], "BoxVolt1", "Copper")
790-
self.aedtapp.modeler.create_box([30, 0, 10], [40, 10, 5], "BoxVolt2", "Copper")
790+
box2 = self.aedtapp.modeler.create_box([30, 0, 10], [40, 10, 5], "BoxVolt2", "Copper")
791791
port = self.aedtapp.create_voltage_source_from_objects(
792792
box1.name, "BoxVolt2", self.aedtapp.AxisDir.XNeg, "Volt1"
793793
)
794794
assert port.name in self.aedtapp.excitation_names
795-
port = self.aedtapp.create_current_source_from_objects("BoxVolt1", "BoxVolt2", self.aedtapp.AxisDir.XPos)
795+
796+
# Create with name
797+
port = self.aedtapp.create_current_source_from_objects(box1.name, box2.name, self.aedtapp.AxisDir.XPos)
798+
assert port
796799
assert port.name in self.aedtapp.excitation_names
800+
# Create with id
801+
port2 = self.aedtapp.create_current_source_from_objects(box1.id, box2.id)
802+
assert port2
803+
assert port2.name in self.aedtapp.excitation_names
804+
# Create with Object3d
805+
port3 = self.aedtapp.create_current_source_from_objects(box1, box2)
806+
assert port3
807+
assert port3.name in self.aedtapp.excitation_names
797808

798809
def test_19_create_lumped_on_sheet(self):
799810
rect = self.aedtapp.modeler.create_rectangle(Plane.XY, [0, 0, 0], [10, 2], name="lump_port", material="Copper")

0 commit comments

Comments
 (0)