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/2148.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Set multiple export ids
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
48 changes: 47 additions & 1 deletion src/ansys/geometry/core/tools/unsupported.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

Expand Down Expand Up @@ -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"]:
Expand Down
24 changes: 23 additions & 1 deletion tests/integration/test_design_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")

Expand All @@ -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))

Expand Down
Loading