Skip to content

Commit f6197b8

Browse files
jacobrkerstetterpre-commit-ci[bot]pyansys-ci-bot
authored
feat: set multiple export ids (#2148)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 8329435 commit f6197b8

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

doc/changelog.d/2148.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Set multiple export ids

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ classifiers = [
2424
]
2525

2626
dependencies = [
27-
"ansys-api-geometry==0.4.68",
27+
"ansys-api-geometry==0.4.69",
2828
"ansys-tools-path>=0.3,<1",
2929
"beartype>=0.11.0,<0.22",
3030
"geomdl>=5,<6",

src/ansys/geometry/core/tools/unsupported.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@
2121
# SOFTWARE.
2222
"""Unsupported functions for the PyAnsys Geometry library."""
2323

24+
from dataclasses import dataclass
2425
from enum import Enum, unique
2526
from typing import TYPE_CHECKING
2627

2728
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier
28-
from ansys.api.geometry.v0.unsupported_pb2 import ExportIdRequest, ImportIdRequest
29+
from ansys.api.geometry.v0.unsupported_pb2 import (
30+
ExportIdRequest,
31+
ImportIdRequest,
32+
SetExportIdsRequest,
33+
)
2934
from ansys.api.geometry.v0.unsupported_pb2_grpc import UnsupportedStub
3035
from ansys.geometry.core.connection import GrpcClient
3136
from ansys.geometry.core.errors import protect_grpc
@@ -49,6 +54,15 @@ class PersistentIdType(Enum):
4954
PRIME_ID = 700
5055

5156

57+
@dataclass
58+
class ExportIdData:
59+
"""Data for exporting persistent ids."""
60+
61+
moniker: str
62+
id_type: PersistentIdType
63+
value: str
64+
65+
5266
class UnsupportedCommands:
5367
"""Provides unsupported commands for PyAnsys Geometry.
5468
@@ -168,6 +182,38 @@ def set_export_id(self, moniker: str, id_type: PersistentIdType, value: str) ->
168182
self._unsupported_stub.SetExportId(request)
169183
self.__id_map = {}
170184

185+
@protect_grpc
186+
@min_backend_version(26, 1, 0)
187+
def set_multiple_export_ids(
188+
self,
189+
export_data: list[ExportIdData],
190+
) -> None:
191+
"""Set multiple persistent ids for the monikers.
192+
193+
Parameters
194+
----------
195+
export_data : list[ExportIdData]
196+
List of export data containing monikers, id types, and values.
197+
198+
Warnings
199+
--------
200+
This method is only available starting on Ansys release 26R1.
201+
"""
202+
request = SetExportIdsRequest(
203+
export_data=[
204+
ExportIdRequest(
205+
moniker=EntityIdentifier(id=data.moniker),
206+
id=data.value,
207+
type=data.id_type.value,
208+
)
209+
for data in export_data
210+
]
211+
)
212+
213+
# Call the gRPC service
214+
self._unsupported_stub.SetExportIds(request)
215+
self.__id_map = {}
216+
171217
def get_body_occurrences_from_import_id(
172218
self, import_id: str, id_type: PersistentIdType
173219
) -> list["Body"]:

tests/integration/test_design_import.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from ansys.geometry.core.math import UNITVECTOR3D_Z, Plane, Point2D, Point3D, UnitVector3D, Vector3D
3535
from ansys.geometry.core.misc import UNITS, Distance
3636
from ansys.geometry.core.sketch import Sketch
37-
from ansys.geometry.core.tools.unsupported import PersistentIdType
37+
from ansys.geometry.core.tools.unsupported import ExportIdData, PersistentIdType
3838

3939
from .conftest import FILES_DIR, IMPORT_FILES_DIR
4040

@@ -212,6 +212,7 @@ def test_open_file(modeler: Modeler, tmp_path_factory: pytest.TempPathFactory):
212212
comp1.extrude_sketch("Top", sketch, 5)
213213

214214
if BackendType.is_core_service(modeler.client.backend_type):
215+
# Set single export ids and verify
215216
modeler.unsupported.set_export_id(base_body.id, PersistentIdType.PRIME_ID, "1")
216217
modeler.unsupported.set_export_id(wheel_body.id, PersistentIdType.PRIME_ID, "2")
217218

@@ -238,6 +239,27 @@ def test_open_file(modeler: Modeler, tmp_path_factory: pytest.TempPathFactory):
238239
assert base_body.faces[0].id in [f.id for f in faces]
239240
assert base_body.edges[0].id in [e.id for e in edges]
240241

242+
# Set multiple export ids at once and verify
243+
export_data = [
244+
ExportIdData(
245+
moniker=base_body.faces[1].id, id_type=PersistentIdType.PRIME_ID, value="5"
246+
),
247+
ExportIdData(
248+
moniker=base_body.edges[1].id, id_type=PersistentIdType.PRIME_ID, value="6"
249+
),
250+
]
251+
modeler.unsupported.set_multiple_export_ids(export_data)
252+
253+
faces2 = modeler.unsupported.get_face_occurrences_from_import_id(
254+
"5", PersistentIdType.PRIME_ID
255+
)
256+
edges2 = modeler.unsupported.get_edge_occurrences_from_import_id(
257+
"6", PersistentIdType.PRIME_ID
258+
)
259+
260+
assert base_body.faces[1].id in [b.id for b in faces2]
261+
assert base_body.edges[1].id in [b.id for b in edges2]
262+
241263
file = tmp_path_factory.mktemp("test_design_import") / "two_cars.scdocx"
242264
design.download(str(file))
243265

0 commit comments

Comments
 (0)