Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1d4aa8d
Add create named selection and get obejcts from named selections
gmalinve Jun 24, 2026
e70435e
chore: adding changelog file 7832.added.md [dependabot-skip]
pyansys-ci-bot Jun 24, 2026
ab68551
add tests to create and get objs in named selection
gmalinve Jun 24, 2026
bad335e
Merge branch 'main' into feat/create_get_named_selections
gmalinve Jun 24, 2026
205c3d4
Merge branch 'main' into feat/create_get_named_selections
gmalinve Jun 30, 2026
2af6278
Merge branch 'main' into feat/create_get_named_selections
gmalinve Jun 30, 2026
904fbe7
Merge branch 'main' into feat/create_get_named_selections
gmalinve Jul 1, 2026
d15e490
add new NamedSelection
gmalinve Jul 3, 2026
7523388
Merge branch 'main' into feat/create_get_named_selections
gmalinve Jul 3, 2026
942c08b
chore: adding changelog file 7832.added.md [dependabot-skip]
pyansys-ci-bot Jul 3, 2026
37f068f
update tests
gmalinve Jul 3, 2026
056c1a7
Add example docstrings
gmalinve Jul 3, 2026
3c3da60
Merge branch 'main' into feat/create_get_named_selections
gmalinve Jul 3, 2026
e7b1597
Add example docstrings
gmalinve Jul 3, 2026
7094dde
Merge branch 'main' into feat/create_get_named_selections
gmalinve Jul 6, 2026
e8f3b6d
Merge branch 'main' into feat/create_get_named_selections
gmalinve Jul 6, 2026
1ce50de
fix icepak tests
gmalinve Jul 6, 2026
de647ce
Merge branch 'main' into feat/create_get_named_selections
gmalinve Jul 7, 2026
b2052d7
remove try/except
gmalinve Jul 7, 2026
02ffc72
remove try/except
gmalinve Jul 7, 2026
9128a29
add AEDT version check
gmalinve Jul 8, 2026
ecf8824
pragma no cover
gmalinve Jul 8, 2026
664ed24
Merge branch 'main' into feat/create_get_named_selections
gmalinve Jul 20, 2026
06c412f
Merge branch 'main' into feat/create_get_named_selections
eblanco-ansys Jul 21, 2026
e481b48
Merge branch 'main' into feat/create_get_named_selections
gmalinve Jul 21, 2026
1d649a6
add warning messages to List methods and update new named selections …
gmalinve Jul 22, 2026
edeb8ab
Merge branch 'main' into feat/create_get_named_selections
gmalinve Jul 22, 2026
40a2b4d
add tests for named selection methods
gmalinve Jul 22, 2026
08e9c35
update docstring
gmalinve Jul 22, 2026
463bdde
update docstrings and logic
gmalinve Jul 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/7832.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add create named selection and get obejcts from named selections
63 changes: 63 additions & 0 deletions src/ansys/aedt/core/modeler/cad/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from ansys.aedt.core.generic.numbers_utils import decompose_variable_value
from ansys.aedt.core.generic.numbers_utils import is_number
from ansys.aedt.core.generic.quaternion import Quaternion
from ansys.aedt.core.internal.errors import AEDTRuntimeError
from ansys.aedt.core.internal.errors import GrpcApiError
from ansys.aedt.core.modeler.cad.components_3d import UserDefinedComponent
from ansys.aedt.core.modeler.cad.elements_3d import EdgePrimitive
Expand Down Expand Up @@ -1236,6 +1237,68 @@ def get_objects_by_material(self, material: str | None = None) -> list:
]
return obj_lst

@pyaedt_function_handler()
def create_named_selection(self, name: str, objects: list[str] | list[int]) -> str:
"""Create a new named selection given objects or face ids.

Parameters
----------
name : str
Name of the named selection.
objects : list of str or int
List of object names or face ids to include in the named selection.

Returns
-------
str
Name of the created named selection.

References
----------
>>> oEditor.CreateNamedSelection
"""
is_str_list = all(isinstance(obj, str) for obj in objects)
is_id_list = all(isinstance(obj, int) for obj in objects)

if is_str_list:
selection_type = "Object"
selection = ", ".join(objects)
elif is_id_list:
selection_type = "Face"
selection = objects

params = ["NAME:NamedSelectionParameters", "Type:=", selection_type, "Selection:=", selection]
attr = ["NAME:Attributes", "Name:=", name, "UDM ID:=", -1]
self.oeditor.CreateNamedSelection(params, attr)
return name

@pyaedt_function_handler
def get_named_selection_objects(self, name: str) -> list:
"""Objects in named selection.

Parameters
----------
name : str
Name of the named selection.

Returns
-------
list
List of objects contained in the named selection.

Reference
---------
>>> oEditor.GetEntityIDsContainedByNamedSelection
"""
try:
self.oeditor.GetNamedSelectionIDByName(name)
except Exception:
raise AEDTRuntimeError("Named selection does not exist.")

entity_ids = self.oeditor.GetEntityIDsContainedByNamedSelection(name)
selected_objects = [self.objects[int(entity_id)] for entity_id in entity_ids]
return selected_objects

@pyaedt_function_handler()
def _get_coordinates_data(self): # pragma: no cover
coord = []
Expand Down
21 changes: 21 additions & 0 deletions tests/system/general/test_primitives_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2563,3 +2563,24 @@ def test_delete_all_points(aedt_app) -> None:

assert result
assert [] == aedt_app.modeler.oeditor.GetPoints()


def test_create_named_selections(aedt_app) -> None:
aedt_app.modeler.create_box([0, 0, 0], [1, 2, 3], name="box1")
aedt_app.modeler.create_box([10, 10, 10], [1, 2, 3], name="box2")

result = aedt_app.modeler.create_named_selection(name="test", objects=aedt_app.modeler.object_names)

assert result == "test"


def test_get_named_selection_objects(aedt_app) -> None:
box1 = aedt_app.modeler.create_box([0, 0, 0], [1, 2, 3], name="box1")
box2 = aedt_app.modeler.create_box([10, 10, 10], [1, 2, 3], name="box2")

aedt_app.modeler.create_named_selection(name="test", objects=aedt_app.modeler.object_names)
objs = aedt_app.modeler.get_named_selection_objects(name="test")
Comment thread
gmalinve marked this conversation as resolved.

assert isinstance(objs, list)
assert box1 in objs
assert box2 in objs
Loading