Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/2063.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent the creation of empty named selections
13 changes: 13 additions & 0 deletions src/ansys/geometry/core/designer/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,20 @@ def create_named_selection(
-------
NamedSelection
Newly created named selection that maintains references to all target entities.

Raises
------
ValueError
If no entities are provided for the named selection. At least
one of the optional parameters must be provided.
"""
# Verify that at least one entity is provided
if not any([bodies, faces, edges, beams, design_points]):
raise ValueError(
"At least one of the following must be provided: "
"bodies, faces, edges, beams, or design_points."
)

named_selection = NamedSelection(
name,
self,
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/test_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,22 @@ def test_named_selections(modeler: Modeler):
assert len(design.named_selections) == 3


def test_empty_named_selection(modeler: Modeler):
"""Test for verifying the creation of an empty ``NamedSelection``."""
# Create your design on the server side
design = modeler.create_design("EmptyNamedSelection_Test")

# Attempting to create an empty NamedSelection raises an error
with pytest.raises(ValueError, match="At least one of the following must be provided:"):
design.create_named_selection("EmptyNS")

# Make sure that passing empty lists also raises an error
with pytest.raises(ValueError, match="At least one of the following must be provided:"):
design.create_named_selection(
"EmptyNS2", bodies=[], faces=[], edges=[], beams=[], design_points=[]
)


def test_named_selection_contents(modeler: Modeler):
"""Test for verifying the correct contents of a ``NamedSelection``."""
# Create your design on the server side
Expand Down
Loading