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 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=10)
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=10)
  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 298, in connect
    channel = _connect_grpc_channel(
        host=LOCALHOST,
    ...<4 lines>...
        certs_dir=certs_dir,
    )
  File "C:\Users\ansys\actions-runner\_work\pysherlock\pysherlock\.venv\Lib\site-packages\ansys\sherlock\core\launcher.py", line 369, in _connect_grpc_channel
    channel = create_channel(
        transport_mode=transport_mode,
    ...<9 lines>...
        ],
    )
  File "C:\Users\ansys\actions-runner\_work\pysherlock\pysherlock\.venv\Lib\site-packages\ansys\sherlock\core\utils\cyberchannel.py", line 149, in create_channel
    return create_mtls_channel(host, port, certs_dir, cert_files, grpc_options)
  File "C:\Users\ansys\actions-runner\_work\pysherlock\pysherlock\.venv\Lib\site-packages\ansys\sherlock\core\utils\cyberchannel.py", line 364, in create_mtls_channel
    raise FileNotFoundError(error_message) from e
FileNotFoundError: Certificate file not found: certs\ca.crt. Ensure that the certificates are present in the 'certs' folder or set the 'ANSYS_GRPC_CERTIFICATES' environment variable.

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(f"Error importing ODB++ archive: {e}")

Total running time of the script: (0 minutes 0.007 seconds)