Note
Go to the end to download the full example code.
Sherlock Project Import in Single Mode#
This example demonstrates how to launch the Sherlock gRPC service in single-project mode, import a project, and handle common exceptions during the import process.
Description Sherlock’s gRPC API enables automation of various workflows, including project management. This script demonstrates how to: - Connect to the Sherlock service in single-project mode. - Import a sample project archive. - Handle import errors gracefully.
import os
from examples.examples_globals import (
get_sherlock_tutorial_path,
get_temp_dir,
store_sherlock_tutorial_path,
)
from ansys.sherlock.core import launcher
from ansys.sherlock.core.errors import SherlockImportProjectZipArchiveSingleModeError
Launch PySherlock service in single-project mode#
Launch the Sherlock service using the specified project path and wait for initialization.
sherlock, ansys_install_path = launcher.launch_and_connect(
port=9093,
single_project_path=os.getcwd(),
# sherlock_command_args="-noGUI",
)
store_sherlock_tutorial_path(ansys_install_path)
Import Sherlock Project in Single Mode#
Import a tutorial project ZIP archive provided with the Sherlock installation.
try:
sherlock.project.import_project_zip_archive_single_mode(
project="Test",
category="Demos",
archive_file=os.path.join(get_sherlock_tutorial_path(), "Auto Relay Project.zip"),
destination_file_directory=get_temp_dir(),
)
print("Tutorial project imported successfully.")
except SherlockImportProjectZipArchiveSingleModeError as e:
print(f"Error importing project: {e}")
Exit Sherlock#
Exit the gRPC connection and shut down Sherlock.
sherlock.common.exit(True)