Note
Go to the end to download the full example code.
Import ODB++ Archive#
This example demonstrates how to launch the Sherlock gRPC service, import an ODB++ archive, and handle common exceptions during the import process.
Description Sherlock’s gRPC API enables automation of various workflows, including importing ODB++ archives. This script demonstrates how to: - Connect to the Sherlock service. - Import an ODB++ archive. - Handle import errors gracefully.
import os
from examples.examples_globals import SHERLOCK_CONNECT_TIMEOUT, get_sherlock_tutorial_path
from ansys.sherlock.core import launcher
from ansys.sherlock.core.errors import SherlockImportODBError
Connect to Sherlock#
Connect to the Sherlock service and ensure proper initialization.
sherlock = launcher.connect(port=9092, timeout=SHERLOCK_CONNECT_TIMEOUT, transport_mode="wnua")
Traceback (most recent call last):
File "C:\Users\ansys\actions-runner\_work\pysherlock\pysherlock\examples\02-importing\import_odb_archive.py", line 57, in <module>
sherlock = launcher.connect(port=9092, timeout=SHERLOCK_CONNECT_TIMEOUT, transport_mode="wnua")
File "C:\Users\ansys\actions-runner\_work\pysherlock\pysherlock\.venv\Lib\site-packages\ansys\sherlock\core\launcher.py", line 324, in connect
raise e
File "C:\Users\ansys\actions-runner\_work\pysherlock\pysherlock\.venv\Lib\site-packages\ansys\sherlock\core\launcher.py", line 306, in connect
_wait_for_sherlock_grpc_ready(channel, timeout)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
File "C:\Users\ansys\actions-runner\_work\pysherlock\pysherlock\.venv\Lib\site-packages\ansys\sherlock\core\launcher.py", line 395, in _wait_for_sherlock_grpc_ready
raise SherlockConnectionError(message="Error starting gRPC service")
ansys.sherlock.core.errors.SherlockConnectionError: gRPC connection error: Error starting gRPC service
Delete Project#
Delete the project if it already exists.
try:
sherlock.project.delete_project("Test")
print("Project deleted successfully.")
except Exception:
pass
Import ODB++ Archive#
Import an ODB++ archive provided with the Sherlock installation.
try:
odb_path = os.path.join(get_sherlock_tutorial_path(), "ODB++ Tutorial.tgz")
sherlock.project.import_odb_archive(
archive_file=odb_path,
process_layer_thickness=True,
include_other_layers=True,
process_cutout_file=True,
guess_part_properties=True,
ims_stackup=True,
project="Test",
cca_name="Card",
)
print("ODB++ archive imported successfully.")
except SherlockImportODBError as e:
print("Error importing ODB++ archive.")
Total running time of the script: (0 minutes 2.015 seconds)