diff --git a/doc/changelog.d/2148.added.md b/doc/changelog.d/2148.added.md new file mode 100644 index 0000000000..76e4676fe7 --- /dev/null +++ b/doc/changelog.d/2148.added.md @@ -0,0 +1 @@ +Set multiple export ids \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 83ab97f67d..e89dd9862a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ classifiers = [ ] dependencies = [ - "ansys-api-geometry==0.4.68", + "ansys-api-geometry==0.4.69", "ansys-tools-path>=0.3,<1", "beartype>=0.11.0,<0.22", "geomdl>=5,<6", diff --git a/src/ansys/geometry/core/tools/unsupported.py b/src/ansys/geometry/core/tools/unsupported.py index 70464b14a1..9252693627 100644 --- a/src/ansys/geometry/core/tools/unsupported.py +++ b/src/ansys/geometry/core/tools/unsupported.py @@ -21,11 +21,16 @@ # SOFTWARE. """Unsupported functions for the PyAnsys Geometry library.""" +from dataclasses import dataclass from enum import Enum, unique from typing import TYPE_CHECKING from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier -from ansys.api.geometry.v0.unsupported_pb2 import ExportIdRequest, ImportIdRequest +from ansys.api.geometry.v0.unsupported_pb2 import ( + ExportIdRequest, + ImportIdRequest, + SetExportIdsRequest, +) from ansys.api.geometry.v0.unsupported_pb2_grpc import UnsupportedStub from ansys.geometry.core.connection import GrpcClient from ansys.geometry.core.errors import protect_grpc @@ -49,6 +54,15 @@ class PersistentIdType(Enum): PRIME_ID = 700 +@dataclass +class ExportIdData: + """Data for exporting persistent ids.""" + + moniker: str + id_type: PersistentIdType + value: str + + class UnsupportedCommands: """Provides unsupported commands for PyAnsys Geometry. @@ -168,6 +182,38 @@ def set_export_id(self, moniker: str, id_type: PersistentIdType, value: str) -> self._unsupported_stub.SetExportId(request) self.__id_map = {} + @protect_grpc + @min_backend_version(26, 1, 0) + def set_multiple_export_ids( + self, + export_data: list[ExportIdData], + ) -> None: + """Set multiple persistent ids for the monikers. + + Parameters + ---------- + export_data : list[ExportIdData] + List of export data containing monikers, id types, and values. + + Warnings + -------- + This method is only available starting on Ansys release 26R1. + """ + request = SetExportIdsRequest( + export_data=[ + ExportIdRequest( + moniker=EntityIdentifier(id=data.moniker), + id=data.value, + type=data.id_type.value, + ) + for data in export_data + ] + ) + + # Call the gRPC service + self._unsupported_stub.SetExportIds(request) + self.__id_map = {} + def get_body_occurrences_from_import_id( self, import_id: str, id_type: PersistentIdType ) -> list["Body"]: diff --git a/tests/integration/test_design_import.py b/tests/integration/test_design_import.py index 13d2b3a35b..39f350d741 100644 --- a/tests/integration/test_design_import.py +++ b/tests/integration/test_design_import.py @@ -34,7 +34,7 @@ from ansys.geometry.core.math import UNITVECTOR3D_Z, Plane, Point2D, Point3D, UnitVector3D, Vector3D from ansys.geometry.core.misc import UNITS, Distance from ansys.geometry.core.sketch import Sketch -from ansys.geometry.core.tools.unsupported import PersistentIdType +from ansys.geometry.core.tools.unsupported import ExportIdData, PersistentIdType from .conftest import FILES_DIR, IMPORT_FILES_DIR @@ -212,6 +212,7 @@ def test_open_file(modeler: Modeler, tmp_path_factory: pytest.TempPathFactory): comp1.extrude_sketch("Top", sketch, 5) if BackendType.is_core_service(modeler.client.backend_type): + # Set single export ids and verify modeler.unsupported.set_export_id(base_body.id, PersistentIdType.PRIME_ID, "1") modeler.unsupported.set_export_id(wheel_body.id, PersistentIdType.PRIME_ID, "2") @@ -238,6 +239,27 @@ def test_open_file(modeler: Modeler, tmp_path_factory: pytest.TempPathFactory): assert base_body.faces[0].id in [f.id for f in faces] assert base_body.edges[0].id in [e.id for e in edges] + # Set multiple export ids at once and verify + export_data = [ + ExportIdData( + moniker=base_body.faces[1].id, id_type=PersistentIdType.PRIME_ID, value="5" + ), + ExportIdData( + moniker=base_body.edges[1].id, id_type=PersistentIdType.PRIME_ID, value="6" + ), + ] + modeler.unsupported.set_multiple_export_ids(export_data) + + faces2 = modeler.unsupported.get_face_occurrences_from_import_id( + "5", PersistentIdType.PRIME_ID + ) + edges2 = modeler.unsupported.get_edge_occurrences_from_import_id( + "6", PersistentIdType.PRIME_ID + ) + + assert base_body.faces[1].id in [b.id for b in faces2] + assert base_body.edges[1].id in [b.id for b in edges2] + file = tmp_path_factory.mktemp("test_design_import") / "two_cars.scdocx" design.download(str(file))