Skip to content

Commit 0b49f0f

Browse files
jonahrbpyansys-ci-botRyanJWardRobPasMue
authored
fix: make import component named selections optional (#2144)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Ryan Ward <[email protected]> Co-authored-by: rward <[email protected]> Co-authored-by: Roberto Pastor Muela <[email protected]>
1 parent d3179d8 commit 0b49f0f

File tree

7 files changed

+80
-5
lines changed

7 files changed

+80
-5
lines changed

doc/changelog.d/2144.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make import component named selections optional

src/ansys/geometry/core/_grpc/_services/v0/designs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ def insert(self, **kwargs) -> dict: # noqa: D102
170170
from ansys.api.dbu.v0.designs_pb2 import InsertRequest
171171

172172
# Create the request - assumes all inputs are valid and of the proper type
173-
request = InsertRequest(filepath=kwargs["filepath"])
173+
request = InsertRequest(
174+
filepath=kwargs["filepath"], import_named_selections=kwargs["import_named_selections"]
175+
)
174176

175177
# Call the gRPC service
176178
_ = self.stub.Insert(request)

src/ansys/geometry/core/designer/component.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,14 @@ def import_named_selections(self) -> None:
19051905
--------
19061906
This method is only available starting on Ansys release 26R1.
19071907
"""
1908+
from ansys.geometry.core.designer import Design
1909+
1910+
if isinstance(self, Design):
1911+
raise ValueError(
1912+
"import_named_selections() cannot be used on a Design object, "
1913+
"it can only be used on a pure Component object."
1914+
)
1915+
19081916
self._component_stub.ImportGroups(ImportGroupsRequest(id=self._grpc_id))
19091917

19101918
design = get_design_from_component(self)

src/ansys/geometry/core/designer/design.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,9 @@ def delete_beam_profile(self, beam_profile: BeamProfile | str) -> None:
973973
@ensure_design_is_active
974974
@min_backend_version(24, 2, 0)
975975
def insert_file(
976-
self, file_location: Path | str, import_options: ImportOptions = ImportOptions()
976+
self,
977+
file_location: Path | str,
978+
import_options: ImportOptions = ImportOptions(),
977979
) -> Component:
978980
"""Insert a file into the design.
979981
@@ -997,7 +999,9 @@ def insert_file(
997999
filepath_server = self._modeler._upload_file(file_location, import_options=import_options)
9981000

9991001
# Insert the file into the design
1000-
self._grpc_client.services.designs.insert(filepath=filepath_server)
1002+
self._grpc_client.services.designs.insert(
1003+
filepath=filepath_server, import_named_selections=import_options.import_named_selections
1004+
)
10011005
self._grpc_client.log.debug(f"File {file_location} successfully inserted into design.")
10021006

10031007
self._update_design_inplace()

src/ansys/geometry/core/misc/options.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class ImportOptions:
4848
Import planes.
4949
import_points : bool = False
5050
Import points.
51+
import_named_selections : bool = True
52+
Import the named selections associated with the root component being inserted.
5153
"""
5254

5355
cleanup_bodies: bool = False
@@ -57,6 +59,7 @@ class ImportOptions:
5759
import_names: bool = False
5860
import_planes: bool = False
5961
import_points: bool = False
62+
import_named_selections: bool = True
6063

6164
def to_dict(self):
6265
"""Provide the dictionary representation of the ImportOptions class."""

tests/_incompatible_tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ backends:
102102
# Bug fix included from 26.1 onwards
103103
- tests/integration/test_design_import.py::test_named_selections_after_file_insert
104104
- tests/integration/test_design_import.py::test_named_selections_after_file_open
105+
- tests/integration/test_design_import.py::test_file_insert_import_named_selections_post_import
105106
# Export body facets add in 26.1
106107
- tests/integration/test_design.py::test_write_body_facets_on_save
107108

@@ -200,6 +201,7 @@ backends:
200201
# Bug fix included from 26.1 onwards
201202
- tests/integration/test_design_import.py::test_named_selections_after_file_insert
202203
- tests/integration/test_design_import.py::test_named_selections_after_file_open
204+
- tests/integration/test_design_import.py::test_file_insert_import_named_selections_post_import
203205
# Export body facets add in 26.1
204206
- tests/integration/test_design.py::test_write_body_facets_on_save
205207

@@ -267,6 +269,7 @@ backends:
267269
# Bug fix included from 26.1 onwards
268270
- tests/integration/test_design_import.py::test_named_selections_after_file_insert
269271
- tests/integration/test_design_import.py::test_named_selections_after_file_open
272+
- tests/integration/test_design_import.py::test_file_insert_import_named_selections_post_import
270273
# Export body facets add in 26.1
271274
- tests/integration/test_design.py::test_write_body_facets_on_save
272275

@@ -298,5 +301,6 @@ backends:
298301
# Bug fix included from 26.1 onwards
299302
- tests/integration/test_design_import.py::test_named_selections_after_file_insert
300303
- tests/integration/test_design_import.py::test_named_selections_after_file_open
304+
- tests/integration/test_design_import.py::test_file_insert_import_named_selections_post_import
301305
# Export body facets add in 26.1
302306
- tests/integration/test_design.py::test_write_body_facets_on_save

tests/integration/test_design_import.py

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from ansys.geometry.core.designer import Component, Design
3333
from ansys.geometry.core.designer.design import DesignFileFormat
3434
from ansys.geometry.core.math import UNITVECTOR3D_Z, Plane, Point2D, Point3D, UnitVector3D, Vector3D
35-
from ansys.geometry.core.misc import UNITS, Distance
35+
from ansys.geometry.core.misc import UNITS, Distance, ImportOptions
3636
from ansys.geometry.core.sketch import Sketch
3737
from ansys.geometry.core.tools.unsupported import ExportIdData, PersistentIdType
3838

@@ -588,7 +588,6 @@ def test_import_scdocx_with_external_docs(modeler: Modeler):
588588
assert len(component.bodies) == 1
589589

590590

591-
@pytest.mark.skip(reason="Temporary skip for build promotion")
592591
def test_named_selections_after_file_insert(modeler: Modeler):
593592
"""Test to verify named selections are imported during inserting a file."""
594593
# Create a new design
@@ -666,3 +665,57 @@ def test_named_selections_after_file_open(modeler: Modeler):
666665
assert set(actual_named_selections) == set(expected_named_selections), (
667666
f"Expected named selections {expected_named_selections}, but got {actual_named_selections}."
668667
)
668+
669+
670+
def test_file_insert_import_named_selections_post_import(modeler: Modeler):
671+
"""Test to verify named selections can be imported after inserting a file."""
672+
# Create a new design
673+
design = modeler.create_design("BugFix_1277429")
674+
675+
# Verify initial named selections count
676+
initial_named_selections_count = len(design.named_selections)
677+
assert initial_named_selections_count == 0, (
678+
f"Expected no named selections initially, but got {initial_named_selections_count}."
679+
)
680+
681+
# Insert the file
682+
file_path = Path(FILES_DIR, "reactorWNS.scdocx")
683+
options = ImportOptions()
684+
options.import_named_selections = False
685+
design.insert_file(file_path, import_options=options)
686+
687+
# Verify initial named selections count
688+
initial_named_selections_count = len(design.named_selections)
689+
assert initial_named_selections_count == 0, (
690+
f"Expected no named selections initially, but got {initial_named_selections_count}."
691+
)
692+
design.components[0].import_named_selections()
693+
# Verify named selections count after importing
694+
updated_named_selections_count = len(design.named_selections)
695+
assert updated_named_selections_count == 9, (
696+
f"Expected 9 named selections after file insertion, but got "
697+
f"{updated_named_selections_count}."
698+
)
699+
700+
# Expected named selections
701+
expected_named_selections = [
702+
"wall_liquid_level",
703+
"wall_tank",
704+
"wall_probe_1",
705+
"wall_probe_2",
706+
"wall_shaft",
707+
"wall_impeller_1",
708+
"wall_shaft_1",
709+
"wall_impeller_2",
710+
"wall_shaft_2",
711+
]
712+
713+
# Verify the names of the named selections
714+
actual_named_selections = [ns.name for ns in design.named_selections]
715+
for ns_name in actual_named_selections:
716+
assert ns_name in expected_named_selections, f"Unexpected named selection: {ns_name}"
717+
718+
# Verify all expected named selections are present
719+
assert set(actual_named_selections) == set(expected_named_selections), (
720+
f"Expected named selections {expected_named_selections}, but got {actual_named_selections}."
721+
)

0 commit comments

Comments
 (0)