Skip to content

Commit

Permalink
Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ansjmoody authored and ansnfernand committed Jan 23, 2025
1 parent 90d135c commit 244b08c
Show file tree
Hide file tree
Showing 32 changed files with 546 additions and 684 deletions.
25 changes: 9 additions & 16 deletions examples/00-importing-project-files/export_aedb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates.
# Copyright (C) 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -42,7 +42,6 @@
# sphinx_gallery_thumbnail_path = './images/sherlock_export_aedb_example.png'

import os
import time

from ansys.sherlock.core import launcher
from ansys.sherlock.core.errors import SherlockExportAEDBError, SherlockImportODBError
Expand All @@ -55,8 +54,6 @@
VERSION = "242"
ANSYS_ROOT = os.getenv("AWP_ROOT" + VERSION)

time.sleep(5) # Allow time for environment setup

sherlock = launcher.launch_sherlock(port=9092)

###############################################################################
Expand All @@ -65,38 +62,34 @@
# Import the ODB++ archive from the Sherlock tutorial directory.

try:
odb_archive_path = os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "ODB++ Tutorial.tgz")
sherlock.project.import_odb_archive(
file_path=odb_archive_path,
allow_subdirectories=True,
include_layers=True,
use_stackup=True,
archive_file=os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "ODB++ Tutorial.tgz"),
process_layer_thickness=True,
include_other_layers=True,
process_cutout_file=True,
guess_part_properties=True,
project="Test",
cca_name="Card",
)
print("ODB++ archive imported successfully.")
except SherlockImportODBError as e:
print(f"Error importing ODB++ archive: {str(e)}")
print(f"Error importing ODB++ archive: {e}")

###############################################################################
# Export AEDB File
# =================
# Export the AEDB file for the "Card" of the "Test" project to the specified path.

time.sleep(5) # Allow time for the project to load completely

try:
aedb_export_path = os.path.join(os.getcwd(), "test.aedb")
sherlock.model.export_aedb(
project="Test",
project_name="Test",
cca_name="Card",
export_file=aedb_export_path,
include_geometry=True,
include_annotations=False,
)
print(f"AEDB file exported successfully to: {aedb_export_path}")
except SherlockExportAEDBError as e:
print(f"Error exporting AEDB: {str(e)}")
print(f"Error exporting AEDB: {e}")

###############################################################################
# Exit Sherlock
Expand Down
20 changes: 8 additions & 12 deletions examples/00-importing-project-files/export_all_mount_points.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates.
# Copyright (C) 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -43,7 +43,6 @@
# sphinx_gallery_thumbnail_path = './images/sherlock_export_mount_points_example.png'

import os
import time

from ansys.sherlock.core import launcher
from ansys.sherlock.core.errors import (
Expand All @@ -59,8 +58,6 @@
VERSION = "242"
ANSYS_ROOT = os.getenv("AWP_ROOT" + VERSION)

time.sleep(5) # Allow time for environment setup

sherlock = launcher.launch_sherlock(port=9092)

###############################################################################
Expand All @@ -69,32 +66,31 @@
# Import the tutorial project zip archive from the Sherlock tutorial directory.

try:
project_zip_path = os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")
sherlock.project.import_project_zip_archive(
project="Tutorial Project", description="Demos", file_path=project_zip_path
project="Test",
category="Demos",
archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")),
)
print("Tutorial project imported successfully.")
except SherlockImportProjectZipArchiveError as e:
print(f"Error importing project zip archive: {str(e)}")
print(f"Error importing project zip archive: {e}")

###############################################################################
# Export All Mount Points
# ========================
# Export all mount points for the "Main Board" to a CSV file.

time.sleep(10) # Allow time for the project to load completely

try:
mount_points_export_path = os.path.join(os.getcwd(), "MountPointsExport.csv")
sherlock.layer.export_all_mount_points(
project="Tutorial Project",
project="Test",
cca_name="Main Board",
file_path=mount_points_export_path,
export_file=mount_points_export_path,
units="DEFAULT",
)
print(f"All mount points exported successfully to: {mount_points_export_path}")
except SherlockExportAllMountPoints as e:
print(f"Error exporting all mount points: {str(e)}")
print(f"Error exporting all mount points: {e}")

###############################################################################
# Exit Sherlock
Expand Down
20 changes: 8 additions & 12 deletions examples/00-importing-project-files/export_all_test_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates.
# Copyright (C) 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -41,7 +41,6 @@
# sphinx_gallery_thumbnail_path = './images/sherlock_export_test_fixtures_example.png'

import os
import time

from ansys.sherlock.core import launcher
from ansys.sherlock.core.errors import (
Expand All @@ -57,8 +56,6 @@
VERSION = "242"
ANSYS_ROOT = os.getenv("AWP_ROOT" + VERSION)

time.sleep(5) # Allow time for environment setup

sherlock = launcher.launch_sherlock(port=9092)

###############################################################################
Expand All @@ -67,32 +64,31 @@
# Import the tutorial project zip archive provided with the Sherlock installation.

try:
project_zip_path = os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")
sherlock.project.import_project_zip_archive(
project="Tutorial Project", description="Demos", file_path=project_zip_path
project="Test",
category="Demos",
archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")),
)
print("Tutorial project imported successfully.")
except SherlockImportProjectZipArchiveError as e:
print(f"Error importing project zip archive: {str(e)}")
print(f"Error importing project zip archive: {e}")

###############################################################################
# Export All Test Fixtures
# =========================
# Export all test fixtures for the "Main Board" to a CSV file.

time.sleep(10) # Allow time for the project to load completely

try:
test_fixtures_export_path = os.path.join(os.getcwd(), "TestFixturesExport.csv")
sherlock.layer.export_all_test_fixtures(
project="Tutorial Project",
project="Test",
cca_name="Main Board",
file_path=test_fixtures_export_path,
export_file=test_fixtures_export_path,
units="DEFAULT",
)
print(f"All test fixtures exported successfully to: {test_fixtures_export_path}")
except SherlockExportAllTestFixtures as e:
print(f"Error exporting all test fixtures: {str(e)}")
print(f"Error exporting all test fixtures: {e}")

###############################################################################
# Exit Sherlock
Expand Down
26 changes: 11 additions & 15 deletions examples/00-importing-project-files/export_all_test_points.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates.
# Copyright (C) 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -41,7 +41,6 @@
# sphinx_gallery_thumbnail_path = './images/sherlock_export_test_points_example.png'

import os
import time

from ansys.sherlock.core import launcher
from ansys.sherlock.core.errors import (
Expand All @@ -57,8 +56,6 @@
VERSION = "242"
ANSYS_ROOT = os.getenv("AWP_ROOT" + VERSION)

time.sleep(5) # Allow time for environment setup

sherlock = launcher.launch_sherlock(port=9092)

###############################################################################
Expand All @@ -67,34 +64,33 @@
# Import the tutorial project zip archive provided with the Sherlock installation.

try:
project_zip_path = os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")
sherlock.project.import_project_zip_archive(
project="Tutorial Project", description="Demos", file_path=project_zip_path
project="Test",
category="Demos",
archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")),
)
print("Tutorial project imported successfully.")
except SherlockImportProjectZipArchiveError as e:
print(f"Error importing project zip archive: {str(e)}")
print(f"Error importing project zip archive: {e}")

###############################################################################
# Export All Test Points
# =======================
# Export all test points for the "Main Board" to a CSV file.

time.sleep(10) # Allow time for the project to load completely

try:
test_points_export_path = os.path.join(os.getcwd(), "TestPointsExport.csv")
sherlock.layer.export_all_test_points(
project="Tutorial Project",
project="Test",
cca_name="Main Board",
file_path=test_points_export_path,
units="DEFAULT",
delimiter="DEFAULT",
encoding="DEFAULT",
export_file=test_points_export_path,
length_units="DEFAULT",
displacement_units="DEFAULT",
force_units="DEFAULT",
)
print(f"All test points exported successfully to: {test_points_export_path}")
except SherlockExportAllTestPointsError as e:
print(f"Error exporting all test points: {str(e)}")
print(f"Error exporting all test points: {e}")

###############################################################################
# Exit Sherlock
Expand Down
19 changes: 8 additions & 11 deletions examples/00-importing-project-files/export_fea_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates.
# Copyright (C) 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -39,7 +39,6 @@
# sphinx_gallery_thumbnail_path = './images/sherlock_export_fea_model_example.png'

import os
import time

from ansys.sherlock.core import launcher
from ansys.sherlock.core.errors import (
Expand All @@ -56,8 +55,6 @@
VERSION = "242"
ANSYS_ROOT = os.getenv("AWP_ROOT" + VERSION)

time.sleep(5) # Allow time for environment setup

sherlock = launcher.launch_sherlock(port=9092)

###############################################################################
Expand All @@ -66,13 +63,14 @@
# Import the tutorial project zip archive provided with the Sherlock installation.

try:
project_zip_path = os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")
sherlock.project.import_project_zip_archive(
project="Tutorial Project", description="Demos", file_path=project_zip_path
project="Test",
category="Demos",
archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")),
)
print("Tutorial project imported successfully.")
except SherlockImportProjectZipArchiveError as e:
print(f"Error importing project zip archive: {str(e)}")
print(f"Error importing project zip archive: {e}")

###############################################################################
# Export FEA Model
Expand All @@ -82,7 +80,7 @@
try:
fea_export_path = os.path.join(os.getcwd(), "export.wbjn")
sherlock.model.export_FEA_model(
project="Tutorial Project",
project="Test",
cca_name="Main Board",
export_file=fea_export_path,
analysis="NaturalFreq",
Expand All @@ -104,20 +102,19 @@
"aspectRatio": 2,
}
],
display_model=True,
display_model=False,
clear_FEA_database=True,
use_FEA_model_id=True,
coordinate_units="mm",
)
print(f"FEA model exported successfully to: {fea_export_path}")
except SherlockExportFEAModelError as e:
print(f"Error exporting FEA model: {str(e)}")
print(f"Error exporting FEA model: {e}")

###############################################################################
# Exit Sherlock
# =============
# Exit the gRPC connection and shut down Sherlock.

time.sleep(120) # Allow time for processing and export
sherlock.common.exit(True)
print("Sherlock gRPC connection closed successfully.")
Loading

0 comments on commit 244b08c

Please sign in to comment.