From 244b08cdf41f34467ad734d5bd9804d933466ecd Mon Sep 17 00:00:00 2001 From: Jeff Moody <110494049+ansjmoody@users.noreply.github.com> Date: Tue, 14 Jan 2025 16:56:13 -0600 Subject: [PATCH] Fix examples --- .../00-importing-project-files/export_aedb.py | 25 ++---- .../export_all_mount_points.py | 20 ++--- .../export_all_test_fixtures.py | 20 ++--- .../export_all_test_points.py | 26 +++--- .../export_fea_model.py | 19 ++-- .../export_net_list.py | 38 ++++---- .../export_part_list.py | 38 ++++---- .../export_project.py | 79 +++++++---------- .../export_trace_model.py | 83 +++++++++--------- .../import_ipc_2581_archive.py | 17 ++-- .../import_odb_archive.py | 20 ++--- .../import_parts_list.py | 49 ++++------- .../import_project_zip_archive_single_mode.py | 19 ++-- .../import_project_zip_file.py | 20 ++--- examples/01-project-configuration/add_cca.py | 29 ++----- .../add_harmonic_event.py | 84 +++++++++--------- .../add_harmonic_profile.py | 87 +++++++++---------- .../add_modeling_region.py | 19 ++-- .../add_potting_region.py | 15 ++-- .../update_laminate_layer.py | 59 ++++++------- .../update_mount_points_by_file.py | 37 ++++---- .../update_part_location.py | 37 ++++---- .../update_part_location_by_file.py | 33 ++++--- .../update_part_modeling_properties.py | 37 ++++---- .../update_parts_list.py | 37 ++++---- .../update_parts_list_properties.py | 46 +++++----- .../update_potting_region.py | 30 +++---- .../update_thermal_maps.py | 42 +++++---- .../get_parts_list_analysis_props.py | 47 +++++----- .../get_random_vibe_inputs_fields.py | 7 +- examples/02-analyses/run_analysis.py | 41 +++------ .../run_harmonic_vibe_strain_map_analysis.py | 70 ++++++--------- 32 files changed, 546 insertions(+), 684 deletions(-) diff --git a/examples/00-importing-project-files/export_aedb.py b/examples/00-importing-project-files/export_aedb.py index 1d079081..6ea0924b 100644 --- a/examples/00-importing-project-files/export_aedb.py +++ b/examples/00-importing-project-files/export_aedb.py @@ -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 @@ -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 @@ -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) ############################################################################### @@ -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 diff --git a/examples/00-importing-project-files/export_all_mount_points.py b/examples/00-importing-project-files/export_all_mount_points.py index 16a1de4b..3e9fbefc 100644 --- a/examples/00-importing-project-files/export_all_mount_points.py +++ b/examples/00-importing-project-files/export_all_mount_points.py @@ -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 @@ -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 ( @@ -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) ############################################################################### @@ -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 diff --git a/examples/00-importing-project-files/export_all_test_fixtures.py b/examples/00-importing-project-files/export_all_test_fixtures.py index 7cc4271d..4e7ea070 100644 --- a/examples/00-importing-project-files/export_all_test_fixtures.py +++ b/examples/00-importing-project-files/export_all_test_fixtures.py @@ -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 @@ -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 ( @@ -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) ############################################################################### @@ -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 diff --git a/examples/00-importing-project-files/export_all_test_points.py b/examples/00-importing-project-files/export_all_test_points.py index b5586d53..3538e055 100644 --- a/examples/00-importing-project-files/export_all_test_points.py +++ b/examples/00-importing-project-files/export_all_test_points.py @@ -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 @@ -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 ( @@ -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) ############################################################################### @@ -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 diff --git a/examples/00-importing-project-files/export_fea_model.py b/examples/00-importing-project-files/export_fea_model.py index 87708d4c..e402786c 100644 --- a/examples/00-importing-project-files/export_fea_model.py +++ b/examples/00-importing-project-files/export_fea_model.py @@ -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 @@ -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 ( @@ -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) ############################################################################### @@ -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 @@ -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", @@ -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.") diff --git a/examples/00-importing-project-files/export_net_list.py b/examples/00-importing-project-files/export_net_list.py index 2c43d2a0..e79da183 100644 --- a/examples/00-importing-project-files/export_net_list.py +++ b/examples/00-importing-project-files/export_net_list.py @@ -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 @@ -39,10 +39,12 @@ # sphinx_gallery_thumbnail_path = './images/sherlock_export_net_list_example.png' import os -import time from ansys.sherlock.core import launcher -from ansys.sherlock.core.errors import SherlockExportNetListError, SherlockImportODBError +from ansys.sherlock.core.errors import ( + SherlockExportNetListError, + SherlockImportProjectZipArchiveError, +) from ansys.sherlock.core.types.common_types import TableDelimiter ############################################################################### @@ -53,29 +55,22 @@ VERSION = "242" ANSYS_ROOT = os.getenv("AWP_ROOT" + VERSION) -time.sleep(5) # Allow time for environment setup - sherlock = launcher.launch_sherlock(port=9092) ############################################################################### -# Import ODB++ Archive -# ===================== -# Import an ODB++ project archive provided with the Sherlock installation. +# Import Tutorial Project +# ======================== +# Import the tutorial project zip 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( - odb_archive_path, - overwrite=True, - create_project=True, - use_guidelines=True, - use_predefined_materials=True, + sherlock.project.import_project_zip_archive( project="Test", - cca_name="Card", + category="Demos", + archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")), ) - print("ODB++ project imported successfully.") -except SherlockImportODBError as e: - print(f"Error importing ODB++ project: {str(e)}") + print("Tutorial project imported successfully.") +except SherlockImportProjectZipArchiveError as e: + print(f"Error importing project zip archive: {e}") ############################################################################### # Export Net List @@ -86,7 +81,7 @@ net_list_path = os.path.join(os.getcwd(), "exportedNetList.csv") sherlock.parts.export_net_list( "Test", - "Card", + "Main Board", net_list_path, col_delimiter=TableDelimiter.COMMA, overwrite_existing=True, @@ -94,13 +89,12 @@ ) print(f"Net list exported successfully to: {net_list_path}") except SherlockExportNetListError as e: - print(f"Error exporting net list: {str(e)}") + print(f"Error exporting net list: {e}") ############################################################################### # Exit Sherlock # ============= # Exit the gRPC connection and shut down Sherlock. -time.sleep(5) # Allow time for any remaining operations sherlock.common.exit(True) print("Sherlock gRPC connection closed successfully.") diff --git a/examples/00-importing-project-files/export_part_list.py b/examples/00-importing-project-files/export_part_list.py index 4156035f..84d11969 100644 --- a/examples/00-importing-project-files/export_part_list.py +++ b/examples/00-importing-project-files/export_part_list.py @@ -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 @@ -39,10 +39,12 @@ # sphinx_gallery_thumbnail_path = './images/sherlock_export_parts_list_example.png' import os -import time from ansys.sherlock.core import launcher -from ansys.sherlock.core.errors import SherlockExportPartsListError, SherlockImportODBError +from ansys.sherlock.core.errors import ( + SherlockExportPartsListError, + SherlockImportProjectZipArchiveError, +) ############################################################################### # Launch PySherlock service @@ -52,29 +54,22 @@ VERSION = "242" ANSYS_ROOT = os.getenv("AWP_ROOT" + VERSION) -time.sleep(5) # Allow time for environment setup - sherlock = launcher.launch_sherlock(port=9092) ############################################################################### -# Import ODB++ Archive -# ===================== -# Import an ODB++ project archive provided with the Sherlock installation. +# Import Tutorial Project +# ======================== +# Import the tutorial project zip 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( - odb_archive_path, - overwrite=True, - create_project=True, - use_guidelines=True, - use_predefined_materials=True, + sherlock.project.import_project_zip_archive( project="Test", - cca_name="Card", + category="Demos", + archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")), ) - print("ODB++ project imported successfully.") -except SherlockImportODBError as e: - print(f"Error importing ODB++ project: {str(e)}") + print("Tutorial project imported successfully.") +except SherlockImportProjectZipArchiveError as e: + print(f"Error importing project zip archive: {e}") ############################################################################### # Export Parts List @@ -83,16 +78,15 @@ try: parts_list_path = os.path.join(os.getcwd(), "exportedParts.csv") - sherlock.parts.export_parts_list("Test", "Card", parts_list_path) + sherlock.parts.export_parts_list("Test", "Main Board", parts_list_path) print(f"Parts list exported successfully to: {parts_list_path}") except SherlockExportPartsListError as e: - print(f"Error exporting parts list: {str(e)}") + print(f"Error exporting parts list: {e}") ############################################################################### # Exit Sherlock # ============= # Exit the gRPC connection and shut down Sherlock. -time.sleep(5) # Allow time for any remaining operations sherlock.common.exit(True) print("Sherlock gRPC connection closed successfully.") diff --git a/examples/00-importing-project-files/export_project.py b/examples/00-importing-project-files/export_project.py index f92c9182..bd3d6d7c 100644 --- a/examples/00-importing-project-files/export_project.py +++ b/examples/00-importing-project-files/export_project.py @@ -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 @@ -39,7 +39,6 @@ # sphinx_gallery_thumbnail_path = './images/sherlock_project_export_example.png' import os -import time from ansys.sherlock.core import launcher from ansys.sherlock.core.errors import ( @@ -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) ############################################################################### @@ -65,11 +62,14 @@ # Import a sample 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("Tutorial Project", "Demos", project_zip_path) - print("Project imported successfully.") + sherlock.project.import_project_zip_archive( + 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: {str(e)}") + print(f"Error importing project: {e}") ############################################################################### # Export Project @@ -79,62 +79,43 @@ # Export with all options enabled try: sherlock.project.export_project( - "Tutorial Project", - export_dfr=True, - export_pcb_layers=True, - export_components=True, - export_nets=True, - export_simulations=True, - export_settings=True, - output_dir=os.getcwd(), - output_file="Exported_Project_All.zip", - overwrite=True, + project_name="Test", + export_design_files=True, + export_result_files=True, + export_archive_results=True, + export_user_files=True, + export_log_files=True, + export_system_data=True, + export_file_dir=os.getcwd(), + export_file_name="Exported_Project_All.zip", + overwrite_existing_file=True, ) print("Project exported successfully with all options enabled.") except SherlockExportProjectError as e: - print(f"Error exporting project (all options): {str(e)}") + print(f"Error exporting project (all options): {e}") # Export with limited options try: sherlock.project.export_project( - "Tutorial Project", - export_dfr=True, - export_pcb_layers=False, - export_components=False, - export_nets=False, - export_simulations=False, - export_settings=False, - output_dir=os.getcwd(), - output_file="Exported_Project_Limited.zip", - overwrite=True, + project_name="Test", + export_design_files=True, + export_result_files=False, + export_archive_results=False, + export_user_files=False, + export_log_files=False, + export_system_data=False, + export_file_dir=os.getcwd(), + export_file_name="Exported_Project_Limited.zip", + overwrite_existing_file=True, ) print("Project exported successfully with limited options.") except SherlockExportProjectError as e: - print(f"Error exporting project (limited options): {str(e)}") - -# Export only the settings -try: - sherlock.project.export_project( - "Tutorial Project", - export_dfr=False, - export_pcb_layers=False, - export_components=False, - export_nets=False, - export_simulations=False, - export_settings=True, - output_dir=os.getcwd(), - output_file="Exported_Project_Settings.zip", - overwrite=True, - ) - print("Project exported successfully with settings only.") -except SherlockExportProjectError as e: - print(f"Error exporting project (settings only): {str(e)}") + print(f"Error exporting project (limited options): {e}") ############################################################################### # Exit Sherlock # ============= # Exit the gRPC connection and shut down Sherlock. -time.sleep(20) # Allow time for any remaining operations sherlock.common.exit(True) print("Sherlock gRPC connection closed successfully.") diff --git a/examples/00-importing-project-files/export_trace_model.py b/examples/00-importing-project-files/export_trace_model.py index a80cc87c..6802ae79 100644 --- a/examples/00-importing-project-files/export_trace_model.py +++ b/examples/00-importing-project-files/export_trace_model.py @@ -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 @@ -40,7 +40,6 @@ # sphinx_gallery_thumbnail_path = './images/sherlock_trace_model_export_example.png' import os -import time from ansys.api.sherlock.v0 import SherlockAnalysisService_pb2, SherlockModelService_pb2 @@ -67,11 +66,14 @@ # Import a sample 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("Tutorial Project", "Demos", project_zip_path) - print("Project imported successfully.") + sherlock.project.import_project_zip_archive( + 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: {str(e)}") + print(f"Error importing project: {e}") ############################################################################### # Export Trace Model @@ -80,59 +82,60 @@ try: copper_1_layer = sherlock.model.createExportTraceCopperLayerParams( - project_name="Tutorial Project", - assembly_name="Main Board", + project_name="Test", + cca_name="Main Board", output_file_path=os.path.join(TESTDIR, "outputfile_path.stp"), - odb_file="copper-01.odb", - include_pins=True, - include_nets=False, - include_components=False, - include_drcs=False, - length_unit="mm", + copper_layer="copper-01.odb", + overwrite=True, + display_after=False, + clear_FEA_database=False, + use_FEA_model_ID=False, + coord_units="mm", mesh_type=SherlockModelService_pb2.MeshType.NONE, - include_solder_pads=False, + is_modeling_region_enabled=False, trace_output_type=SherlockModelService_pb2.TraceOutputType.ALL_REGIONS, element_order=SherlockAnalysisService_pb2.ElementOrder.Linear, - trace_thickness=1.0, - trace_thickness_unit="mm", - trace_simplification_factor=2, - include_vias=False, - via_diameter=1.0, - via_diameter_unit="mm", - via_height=1.0, + max_mesh_size=1.0, + max_mesh_size_units="mm", + max_holes_per_trace=3, + is_drill_hole_modeling_enabled=False, + drill_hole_min_diameter=1.0, + drill_hole_min_diameter_units="mm", + drill_hole_max_edge_length=1.0, + drill_hole_max_edge_length_units="mm", ) copper_2_layer = sherlock.model.createExportTraceCopperLayerParams( - project_name="Tutorial Project", - assembly_name="Main Board", + project_name="Test", + cca_name="Main Board", output_file_path=os.path.join(TESTDIR, "outputfile_path2.stp"), - odb_file="copper-02.odb", - include_pins=True, - include_nets=False, - include_components=False, - include_drcs=False, - length_unit="mm", + copper_layer="copper-02.odb", + overwrite=True, + display_after=False, + clear_FEA_database=False, + use_FEA_model_ID=False, + coord_units="mm", mesh_type=SherlockModelService_pb2.MeshType.NONE, - include_solder_pads=False, + is_modeling_region_enabled=False, trace_output_type=SherlockModelService_pb2.TraceOutputType.ALL_REGIONS, element_order=SherlockAnalysisService_pb2.ElementOrder.Linear, - trace_thickness=1.0, - trace_thickness_unit="mm", - trace_simplification_factor=2, - include_vias=False, - via_diameter=1.0, - via_diameter_unit="mm", - via_height=1.0, + max_mesh_size=1.0, + max_mesh_size_units="mm", + max_holes_per_trace=3, + is_drill_hole_modeling_enabled=False, + drill_hole_min_diameter=1.0, + drill_hole_min_diameter_units="mm", + drill_hole_max_edge_length=1.0, + drill_hole_max_edge_length_units="mm", ) sherlock.model.exportTraceModel([copper_1_layer, copper_2_layer]) print("Trace model exported successfully.") except SherlockModelServiceError as e: - print(f"Error exporting trace model: {str(e)}") + print(f"Error exporting trace model: {e}") ############################################################################### # Exit Sherlock # ============= # Exit the gRPC connection and shut down Sherlock. -time.sleep(5) # Allow time for any remaining operations sherlock.common.exit(True) print("Sherlock gRPC connection closed successfully.") diff --git a/examples/00-importing-project-files/import_ipc_2581_archive.py b/examples/00-importing-project-files/import_ipc_2581_archive.py index b2c88197..f7c150b4 100644 --- a/examples/00-importing-project-files/import_ipc_2581_archive.py +++ b/examples/00-importing-project-files/import_ipc_2581_archive.py @@ -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 @@ -46,7 +46,6 @@ # sphinx_gallery_thumbnail_path = './images/import_ipc2581_example.png' import os -import time from ansys.sherlock.core import launcher from ansys.sherlock.core.errors import SherlockImportIpc2581Error @@ -69,14 +68,18 @@ try: ipc2581_path = os.path.join(os.getcwd(), "IPC2581A-TestCase2.cvg") sherlock.project.import_ipc2581_archive( - file_path=ipc2581_path, allow_subdirectories=True, include_layers=True + archive_file=ipc2581_path, + include_other_layers=True, + guess_part_properties=True, + project="Test", + cca_name=None, + polyline_simplification=False, + polyline_tolerance=0.1, + polyline_tolerance_units="mm", ) print("IPC-2581 archive imported successfully.") except SherlockImportIpc2581Error as e: - print(f"Error importing IPC-2581 archive: {str(e)}") - -# Wait for 30 seconds to ensure all processes are completed. -time.sleep(30) + print(f"Error importing IPC-2581 archive: {e}") ############################################################################### # Exit Sherlock diff --git a/examples/00-importing-project-files/import_odb_archive.py b/examples/00-importing-project-files/import_odb_archive.py index 6e50698f..1ec18208 100644 --- a/examples/00-importing-project-files/import_odb_archive.py +++ b/examples/00-importing-project-files/import_odb_archive.py @@ -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 @@ -39,7 +39,6 @@ # sphinx_gallery_thumbnail_path = './images/sherlock_odb_import_example.png' import os -import time from ansys.sherlock.core import launcher from ansys.sherlock.core.errors import SherlockImportODBError @@ -58,28 +57,27 @@ # Import ODB++ Archive # ===================== # Import an ODB++ archive provided with the Sherlock installation. -# Specify project and CCA (Circuit Card Assembly) name arguments. try: odb_path = os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "ODB++ Tutorial.tgz") sherlock.project.import_odb_archive( - odb_path, - include_components=True, - include_nets=True, - include_parts=True, - include_drcs=True, - project="Tutorial", + 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: {str(e)}") + print(f"Error importing ODB++ archive: {e}") ############################################################################### # Exit Sherlock # ============= # Exit the gRPC connection and shut down Sherlock. -time.sleep(5) # Allow time for any remaining operations sherlock.common.exit(True) print("Sherlock gRPC connection closed successfully.") diff --git a/examples/00-importing-project-files/import_parts_list.py b/examples/00-importing-project-files/import_parts_list.py index 304a916c..4bc11ee6 100644 --- a/examples/00-importing-project-files/import_parts_list.py +++ b/examples/00-importing-project-files/import_parts_list.py @@ -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 @@ -48,10 +48,12 @@ # sphinx_gallery_thumbnail_path = './images/import_odb_and_parts_list_example.png' import os -import time from ansys.sherlock.core import launcher -from ansys.sherlock.core.errors import SherlockImportODBError, SherlockImportPartsListError +from ansys.sherlock.core.errors import ( + SherlockImportPartsListError, + SherlockImportProjectZipArchiveError, +) ############################################################################### # Launch PySherlock service @@ -64,52 +66,35 @@ sherlock = launcher.launch_sherlock(port=9092) ############################################################################### -# Import ODB++ Archive -# ===================== -# Import an ODB++ archive with specified project and CCA names. +# Import Tutorial Project +# ======================== +# Import the tutorial project zip archive from the Sherlock tutorial directory. try: - odb_path = os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "ODB++ Tutorial.tgz") - sherlock.project.import_odb_archive( - file_path=odb_path, - allow_subdirectories=True, - include_layers=True, - use_stackup=True, - use_materials=True, + sherlock.project.import_project_zip_archive( project="Test", - cca_name="Card", + category="Demos", + archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")), ) - print("ODB++ archive imported successfully.") -except SherlockImportODBError as e: - print(f"Error importing ODB++ archive: {str(e)}") + print("Tutorial project imported successfully.") +except SherlockImportProjectZipArchiveError as e: + print(f"Error importing project zip archive: {e}") ############################################################################### # Import Parts List # ================== -# Import parts lists with different settings for the "Test" project and "Card" CCA. +# Import parts list for the "Test" project and "Card" CCA. try: parts_list_path = os.path.join(os.getcwd(), "partslist.csv") - # Import parts list with validation enabled sherlock.parts.import_parts_list( - project="Test", cca_name="Card", file_path=parts_list_path, validate=True + project="Test", cca_name="Main Board", import_file=parts_list_path, import_as_user_src=True ) print("Parts list imported successfully with validation.") except SherlockImportPartsListError as e: - print(f"Error importing parts list with validation: {str(e)}") + print(f"Error importing parts list with validation: {e}") -try: - # Import parts list without validation - sherlock.parts.import_parts_list( - project="Test", cca_name="Card", file_path=parts_list_path, validate=False - ) - print("Parts list imported successfully without validation.") -except SherlockImportPartsListError as e: - print(f"Error importing parts list without validation: {str(e)}") - -# Wait for 5 seconds to ensure all processes are completed. -time.sleep(5) ############################################################################### # Exit Sherlock diff --git a/examples/00-importing-project-files/import_project_zip_archive_single_mode.py b/examples/00-importing-project-files/import_project_zip_archive_single_mode.py index 0eec4d2b..60f588f4 100644 --- a/examples/00-importing-project-files/import_project_zip_archive_single_mode.py +++ b/examples/00-importing-project-files/import_project_zip_archive_single_mode.py @@ -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 @@ -39,7 +39,6 @@ # sphinx_gallery_thumbnail_path = './images/sherlock_import_single_mode_example.png' import os -import time from ansys.sherlock.core import launcher from ansys.sherlock.core.errors import SherlockImportProjectZipArchiveSingleModeError @@ -51,11 +50,8 @@ VERSION = "242" ANSYS_ROOT = os.getenv("AWP_ROOT" + VERSION) -PROJECT_PATH = "C:\\temp" -time.sleep(5) # Allow time for environment setup - -sherlock = launcher.launch_sherlock(port=9092, single_project_path=PROJECT_PATH) +sherlock = launcher.launch_sherlock(port=9092, single_project_path=os.getcwd()) ############################################################################### # Import Sherlock Project in Single Mode @@ -63,19 +59,20 @@ # Import a 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_single_mode( - "Tutorial Project", "Demos", project_zip_path, os.getcwd() + project="Test", + category="Demos", + archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")), + destination_file_directory=os.getcwd(), ) - print("Project imported successfully.") + print("Tutorial project imported successfully.") except SherlockImportProjectZipArchiveSingleModeError as e: - print(f"Error importing project: {str(e)}") + print(f"Error importing project: {e}") ############################################################################### # Exit Sherlock # ============= # Exit the gRPC connection and shut down Sherlock. -time.sleep(10) # Allow time for any remaining operations sherlock.common.exit(True) print("Sherlock gRPC connection closed successfully.") diff --git a/examples/00-importing-project-files/import_project_zip_file.py b/examples/00-importing-project-files/import_project_zip_file.py index 5033e67c..dcf76e5b 100644 --- a/examples/00-importing-project-files/import_project_zip_file.py +++ b/examples/00-importing-project-files/import_project_zip_file.py @@ -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 # # @@ -46,7 +46,6 @@ # sphinx_gallery_thumbnail_path = './images/sherlock_import_example.png' import os -import time from ansys.sherlock.core import launcher from ansys.sherlock.core.errors import SherlockImportProjectZipArchiveError @@ -60,22 +59,22 @@ VERSION = "242" ANSYS_ROOT = os.getenv("AWP_ROOT" + VERSION) -time.sleep(5) # Allow time for environment setup - sherlock = launcher.launch_sherlock(port=9092) ############################################################################### # Import Sherlock Project # ======================== -# -# Import a tutorial project ZIP archive provided with Sherlock installation. +# Import the tutorial project zip archive from the Sherlock tutorial directory. try: - project_path = os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip") - sherlock.project.import_project_zip_archive("Tutorial Project", "Demos", project_path) - print("Project imported successfully.") + sherlock.project.import_project_zip_archive( + 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: {str(e)}") + print(f"Error importing project: {e}") ############################################################################### # Exit Sherlock @@ -83,6 +82,5 @@ # # Exit the gRPC connection and shut down Sherlock. -time.sleep(10) # Allow time for any remaining operations sherlock.common.exit(True) print("Sherlock gRPC connection closed successfully.") diff --git a/examples/01-project-configuration/add_cca.py b/examples/01-project-configuration/add_cca.py index 7a2a1612..730bdb90 100644 --- a/examples/01-project-configuration/add_cca.py +++ b/examples/01-project-configuration/add_cca.py @@ -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 @@ -42,7 +42,6 @@ # sphinx_gallery_thumbnail_path = './images/add_cca_and_import_odb_example.png' import os -import time from ansys.sherlock.core import launcher from ansys.sherlock.core.errors import SherlockAddCCAError, SherlockImportODBError @@ -58,27 +57,20 @@ sherlock = launcher.launch_sherlock(port=9092) ############################################################################### -# Import ODB++ Archive -# ===================== -# Import the ODB++ archive from the Sherlock tutorial directory. +# Import Tutorial Project +# ======================== +# Import the tutorial project zip 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, - project="Tutorial", - cca_name="Card", + sherlock.project.import_project_zip_archive( + project="Test", + category="Demos", + archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")), ) - print("ODB++ archive imported successfully.") + print("Tutorial project imported successfully.") except SherlockImportODBError as e: print(f"Error importing ODB++ archive: {str(e)}") -# Wait for 5 seconds to ensure the import is complete -time.sleep(5) - ############################################################################### # Add CCAs to Project # =================== @@ -121,9 +113,6 @@ except SherlockAddCCAError as e: print(f"Error adding CCA: {str(e)}") -# Wait for 20 seconds before closing the connection -time.sleep(20) - ############################################################################### # Exit Sherlock # ============= diff --git a/examples/01-project-configuration/add_harmonic_event.py b/examples/01-project-configuration/add_harmonic_event.py index a2560f83..e9c01976 100644 --- a/examples/01-project-configuration/add_harmonic_event.py +++ b/examples/01-project-configuration/add_harmonic_event.py @@ -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 @@ -44,10 +44,13 @@ # sphinx_gallery_thumbnail_path = './images/add_harmonic_event_example.png' import os -import time from ansys.sherlock.core import launcher -from ansys.sherlock.core.errors import SherlockAddHarmonicEventError +from ansys.sherlock.core.errors import ( + SherlockAddHarmonicEventError, + SherlockCreateLifePhaseError, + SherlockImportProjectZipArchiveError, +) ############################################################################### # Launch PySherlock service @@ -59,38 +62,41 @@ sherlock = launcher.launch_sherlock(port=9092) -# Wait for 5 seconds to ensure service is running -time.sleep(5) - ############################################################################### -# Import ODB++ Archive -# ===================== -# Import the ODB++ archive from the Sherlock tutorial directory. - -sherlock.project.import_odb_archive( - file_path=os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "ODB++ Tutorial.tgz"), - allow_subdirectories=True, - include_layers=True, - use_stackup=True, - project="Test", - cca_name="Card", -) -print("ODB++ archive imported successfully.") +# Import Tutorial Project +# ======================== +# Import the tutorial project zip archive from the Sherlock tutorial directory. + +try: + sherlock.project.import_project_zip_archive( + 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: {e}") + +phase_name = "Life Phase Example" ############################################################################### # Create Lifecycle Phase # ======================= # Create a new lifecycle phase called "Example" in the "Test" project. -sherlock.lifecycle.create_life_phase( - project="Test", - phase_name="Example", - time_duration=1.5, - time_units="sec", - cycle_count=4.0, - cycle_units="COUNT", -) -print("Lifecycle phase 'Example' created successfully.") +try: + sherlock.lifecycle.create_life_phase( + project="Test", + phase_name=phase_name, + duration=1.5, + duration_units="sec", + num_of_cycles=4.0, + cycle_type="COUNT", + description="Example phase", + ) + print("Lifecycle phase 'Example' created successfully.") +except SherlockCreateLifePhaseError as e: + print(f"Error creating lifecycle phase: {e}") ############################################################################### # Add Harmonic Event to Lifecycle Phase @@ -100,24 +106,22 @@ try: sherlock.lifecycle.add_harmonic_event( project="Test", - phase_name="Example", + phase_name=phase_name, event_name="Event1", - time_duration=1.5, - time_units="sec", - cycle_count=4.0, - cycle_units="PER MIN", - frequency=5, - direction="45,45", - load_type="Uniaxial", - components="2,4,5", + duration=1.5, + duration_units="sec", + num_of_cycles=4.0, + cycle_type="PER MIN", + sweep_rate=5, + orientation="23.45, 34.56", + profile_type="Uniaxial", + load_direction="2,4,5", + description="Harmonic Event Example", ) print("Harmonic event 'Event1' added successfully.") except SherlockAddHarmonicEventError as e: print(f"Error adding harmonic event: {str(e)}") -# Wait for 5 seconds to ensure all processes are completed -time.sleep(5) - ############################################################################### # Exit Sherlock # ============= diff --git a/examples/01-project-configuration/add_harmonic_profile.py b/examples/01-project-configuration/add_harmonic_profile.py index 48e2c1bf..c91a8402 100644 --- a/examples/01-project-configuration/add_harmonic_profile.py +++ b/examples/01-project-configuration/add_harmonic_profile.py @@ -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 @@ -46,10 +46,9 @@ # sphinx_gallery_thumbnail_path = './images/add_harmonic_vibe_profiles_example.png' import os -import time from ansys.sherlock.core import launcher -from ansys.sherlock.core.errors import SherlockAddHarmonicVibeProfilesError, SherlockImportODBError +from ansys.sherlock.core.errors import SherlockImportProjectZipArchiveError ############################################################################### # Launch PySherlock service @@ -61,26 +60,23 @@ sherlock = launcher.launch_sherlock(port=9092) -# Wait for service to initialize -time.sleep(5) - ############################################################################### -# Import ODB++ Archive -# ===================== -# Import the ODB++ archive from the Sherlock tutorial directory. +# Import Tutorial Project +# ======================== +# Import the tutorial project zip archive from the Sherlock tutorial directory. try: - sherlock.project.import_odb_archive( - file_path=os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "ODB++ Tutorial.tgz"), - allow_subdirectories=True, - include_layers=True, - use_stackup=True, - project="Tutorial", - cca_name="Card", + sherlock.project.import_project_zip_archive( + project="Test", + category="Demos", + archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")), ) - print("ODB++ archive imported successfully.") -except SherlockImportODBError as e: - print(f"Error importing ODB++ archive: {str(e)}") + print("Tutorial project imported successfully.") +except SherlockImportProjectZipArchiveError as e: + print(f"Error importing project zip archive: {e}") + +phase_name = "Life Phase Example" +event_name = "Event1" ############################################################################### # Create Lifecycle Phase and Add Harmonic Event @@ -91,46 +87,43 @@ # Create lifecycle phase sherlock.lifecycle.create_life_phase( project="Test", - phase_name="Example", - time_duration=1.5, - time_units="sec", - cycle_count=4.0, - cycle_units="COUNT", + phase_name=phase_name, + duration=1.5, + duration_units="sec", + num_of_cycles=4.0, + cycle_type="COUNT", + description="Example lifecycle phase.", ) - print("Lifecycle phase 'Example' created successfully.") + print(f"Lifecycle phase {phase_name} created successfully.") # Add harmonic event to lifecycle phase sherlock.lifecycle.add_harmonic_event( project="Test", - phase_name="Example", - event_name="Event1", - time_duration=1.5, - time_units="sec", - cycle_count=4.0, - cycle_units="PER MIN", - frequency=5, - direction="45,45", - load_type="Uniaxial", - components="2,4,5", + phase_name=phase_name, + event_name=event_name, + duration=1.5, + duration_units="sec", + num_of_cycles=4.0, + cycle_type="PER MIN", + sweep_rate=5, + orientation="45,45", + profile_type="Triaxial", + load_direction="2,4,5", + description="Example harmonic event.", ) print("Harmonic event 'Event1' added successfully.") -except SherlockAddHarmonicVibeProfilesError as e: - print(f"Error adding harmonic event: {str(e)}") - -############################################################################### -# Add Harmonic Vibration Profiles -# =============================== -# Add harmonic vibration profiles to the lifecycle phase. - -try: + # Add harmonic vibration profiles to the lifecycle phase. sherlock.lifecycle.add_harmonic_vibe_profiles( project="Test", - profiles=[("Example", "Event1", "Profile1", "HZ", "G", [(10, 1), (1000, 1)], "")], + harmonic_vibe_profiles=[ + (phase_name, event_name, "Profile z axis", "HZ", "G", [(10, 1), (1000, 1)], "z") + ], ) print("Harmonic vibration profiles added successfully.") -except SherlockAddHarmonicVibeProfilesError as e: - print(f"Error adding harmonic vibration profiles: {str(e)}") + +except Exception as e: + print("Error creating life phase, harmonic event, or harmonic vibe profiles") ############################################################################### # Exit Sherlock diff --git a/examples/01-project-configuration/add_modeling_region.py b/examples/01-project-configuration/add_modeling_region.py index c3977c03..7e5ae16a 100644 --- a/examples/01-project-configuration/add_modeling_region.py +++ b/examples/01-project-configuration/add_modeling_region.py @@ -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 @@ -42,7 +42,6 @@ # sphinx_gallery_thumbnail_path = './images/add_modeling_region_example.png' import os -import time from ansys.sherlock.core import launcher from ansys.sherlock.core.errors import SherlockAddModelingRegionError, SherlockImportODBError @@ -63,9 +62,6 @@ sherlock = launcher.launch_sherlock(port=9092) -# Wait for service to initialize -time.sleep(5) - ############################################################################### # Import ODB++ Archive # ===================== @@ -73,16 +69,17 @@ try: sherlock.project.import_odb_archive( - file_path=os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "ODB++ Tutorial.tgz"), - 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}") ############################################################################### # Create Modeling Regions @@ -202,7 +199,7 @@ sherlock.layer.add_modeling_region("Test", modeling_regions) print("Modeling regions added successfully.") except SherlockAddModelingRegionError as e: - print(f"Error adding modeling regions: {str(e)}") + print(f"Error adding modeling regions: {e}") ############################################################################### # Exit Sherlock diff --git a/examples/01-project-configuration/add_potting_region.py b/examples/01-project-configuration/add_potting_region.py index 27231357..e58e1fdd 100644 --- a/examples/01-project-configuration/add_potting_region.py +++ b/examples/01-project-configuration/add_potting_region.py @@ -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 @@ -63,16 +63,17 @@ try: sherlock.project.import_odb_archive( - file_path=os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "ODB++ Tutorial.tgz"), - 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}") ############################################################################### # Add Potting Region @@ -101,7 +102,7 @@ ) print("Potting region added successfully.") except SherlockAddPottingRegionError as e: - print(f"Error adding potting region: {str(e)}") + print(f"Error adding potting region: {e}") ############################################################################### # Exit Sherlock diff --git a/examples/01-project-configuration/update_laminate_layer.py b/examples/01-project-configuration/update_laminate_layer.py index 9af734fd..da698f54 100644 --- a/examples/01-project-configuration/update_laminate_layer.py +++ b/examples/01-project-configuration/update_laminate_layer.py @@ -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 @@ -44,7 +44,10 @@ import os from ansys.sherlock.core import launcher -from ansys.sherlock.core.errors import SherlockImportODBError, SherlockUpdateLaminateLayerError +from ansys.sherlock.core.errors import ( + SherlockImportProjectZipArchiveError, + SherlockUpdateLaminateLayerError, +) ############################################################################### # Launch PySherlock service @@ -57,47 +60,45 @@ sherlock = launcher.launch_sherlock(port=9092) ############################################################################### -# Import ODB++ Archive -# ===================== -# Import the ODB++ archive from the Sherlock tutorial directory. +# Import Tutorial Project +# ======================== +# Import the tutorial project zip 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, + sherlock.project.import_project_zip_archive( project="Test", - cca_name="Card", + category="Demos", + archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")), ) - print("ODB++ archive imported successfully.") -except SherlockImportODBError as e: - print(f"Error importing ODB++ archive: {str(e)}") + print("Tutorial project imported successfully.") +except SherlockImportProjectZipArchiveError as e: + print(f"Error importing project zip archive: {e}") ############################################################################### # Update Laminate Layer Properties # ================================= -# Update the laminate layer properties for the "Card" of the "Test" project. +# Update the laminate layer properties for the "Main Board" of the "Test" project. try: sherlock.stackup.update_laminate_layer( - project_name="Test", - cca_name="Card", - layer_number="2", - layer_material="Generic", - layer_type="FR-4", - layer_material_name="Generic FR-4", - layer_thickness=0.015, - layer_thickness_unit="in", - layer_glass_styles=[("106", 68.0, 0.015, "in")], - dielectric_material="E-GLASS", - conductive_material="COPPER", - conductive_thickness="0.0", + project="Test", + cca_name="Main Board", + layer="2", + manufacturer="Generic", + grade="Cyanate Ester", + material="Generic CE Quartz", + thickness=0.015, + thickness_unit="in", + construction_style="106", + glass_construction=[("106", 71.0, 0.015, "in")], + fiber_material="QUARTZ", + conductor_material="GOLD", + conductor_percent="10.0", ) + print("Laminate layer properties updated successfully.") except SherlockUpdateLaminateLayerError as e: - print(f"Error updating laminate layer properties: {str(e)}") + print(f"Error updating laminate layer properties: {e}") ############################################################################### # Exit Sherlock diff --git a/examples/01-project-configuration/update_mount_points_by_file.py b/examples/01-project-configuration/update_mount_points_by_file.py index 162c1b8f..6cdf03cb 100644 --- a/examples/01-project-configuration/update_mount_points_by_file.py +++ b/examples/01-project-configuration/update_mount_points_by_file.py @@ -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 @@ -48,7 +48,10 @@ import os from ansys.sherlock.core import launcher -from ansys.sherlock.core.errors import SherlockImportODBError, SherlockUpdateMountPointsByFileError +from ansys.sherlock.core.errors import ( + SherlockImportProjectZipArchiveError, + SherlockUpdateMountPointsByFileError, +) ############################################################################### # Launch PySherlock service @@ -61,23 +64,19 @@ sherlock = launcher.launch_sherlock(port=9092) ############################################################################### -# Import ODB++ Archive -# ===================== -# Import the ODB++ archive from the Sherlock tutorial directory. +# Import Tutorial Project +# ======================== +# Import the tutorial project zip 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, - project="Tutorial", - cca_name="Card", + sherlock.project.import_project_zip_archive( + project="Test", + category="Demos", + archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")), ) - print("ODB++ archive imported successfully.") -except SherlockImportODBError as e: - print(f"Error importing ODB++ archive: {str(e)}") + print("Tutorial project imported successfully.") +except SherlockImportProjectZipArchiveError as e: + print(f"Error importing project zip archive: {e}") ############################################################################### # Update Mount Points by File @@ -88,13 +87,13 @@ try: sherlock.layer.update_mount_points_by_file( - project_name="Tutorial", - cca_name="Card", + project="Test", + cca_name="Main Board", file_path=csv_file_path, ) print("Mount points updated successfully using the CSV file.") except SherlockUpdateMountPointsByFileError as e: - print(f"Error updating mount points by file: {str(e)}") + print(f"Error updating mount points by file: {e}") ############################################################################### # Exit Sherlock diff --git a/examples/01-project-configuration/update_part_location.py b/examples/01-project-configuration/update_part_location.py index b1bcd65d..d3a7a93c 100644 --- a/examples/01-project-configuration/update_part_location.py +++ b/examples/01-project-configuration/update_part_location.py @@ -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 @@ -44,7 +44,10 @@ import os from ansys.sherlock.core import launcher -from ansys.sherlock.core.errors import SherlockImportODBError, SherlockUpdatePartsLocationsError +from ansys.sherlock.core.errors import ( + SherlockImportProjectZipArchiveError, + SherlockUpdatePartsLocationsError, +) ############################################################################### # Launch PySherlock service @@ -57,23 +60,19 @@ sherlock = launcher.launch_sherlock(port=9092) ############################################################################### -# Import ODB++ Archive -# ===================== -# Import the ODB++ archive from the Sherlock tutorial directory. +# Import Tutorial Project +# ======================== +# Import the tutorial project zip 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, + sherlock.project.import_project_zip_archive( project="Test", - cca_name="Card", + category="Demos", + archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")), ) - print("ODB++ archive imported successfully.") -except SherlockImportODBError as e: - print(f"Error importing ODB++ archive: {str(e)}") + print("Tutorial project imported successfully.") +except SherlockImportProjectZipArchiveError as e: + print(f"Error importing project zip archive: {e}") ############################################################################### # Update Part Locations @@ -86,13 +85,13 @@ ("J1", "-3.55", "-2.220446049250313E-16", "90", "in", "TOP", "False"), ] sherlock.parts.update_parts_locations( - project_name="Test", - cca_name="Card", - parts_data=part_locations, + project="Test", + cca_name="Main Board", + part_loc=part_locations, ) print("Part locations updated successfully.") except SherlockUpdatePartsLocationsError as e: - print(f"Error updating part locations: {str(e)}") + print(f"Error updating part locations: {e}") ############################################################################### # Exit Sherlock diff --git a/examples/01-project-configuration/update_part_location_by_file.py b/examples/01-project-configuration/update_part_location_by_file.py index 8d002b36..b098e24b 100644 --- a/examples/01-project-configuration/update_part_location_by_file.py +++ b/examples/01-project-configuration/update_part_location_by_file.py @@ -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 @@ -49,7 +49,7 @@ from ansys.sherlock.core import launcher from ansys.sherlock.core.errors import ( - SherlockImportODBError, + SherlockImportProjectZipArchiveError, SherlockUpdatePartsLocationsByFileError, ) @@ -64,23 +64,19 @@ sherlock = launcher.launch_sherlock(port=9092) ############################################################################### -# Import ODB++ Archive -# ===================== -# Import the ODB++ archive from the Sherlock tutorial directory. +# Import Tutorial Project +# ======================== +# Import the tutorial project zip 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, + sherlock.project.import_project_zip_archive( project="Test", - cca_name="Card", + category="Demos", + archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")), ) - print("ODB++ archive imported successfully.") -except SherlockImportODBError as e: - print(f"Error importing ODB++ archive: {str(e)}") + print("Tutorial project imported successfully.") +except SherlockImportProjectZipArchiveError as e: + print(f"Error importing project zip archive: {e}") ############################################################################### # Update Part Locations by File @@ -91,13 +87,14 @@ try: sherlock.parts.update_parts_locations_by_file( - project_name="Test", - cca_name="Card", + project="Test", + cca_name="Main Board", file_path=csv_file_path, + numeric_format="JAPANESE", ) print("Part locations updated successfully using the CSV file.") except SherlockUpdatePartsLocationsByFileError as e: - print(f"Error updating part locations by file: {str(e)}") + print(f"Error updating part locations by file: {e}") ############################################################################### # Exit Sherlock diff --git a/examples/01-project-configuration/update_part_modeling_properties.py b/examples/01-project-configuration/update_part_modeling_properties.py index ab5ddfa2..73d94112 100644 --- a/examples/01-project-configuration/update_part_modeling_properties.py +++ b/examples/01-project-configuration/update_part_modeling_properties.py @@ -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 @@ -44,7 +44,10 @@ import os from ansys.sherlock.core import launcher -from ansys.sherlock.core.errors import SherlockImportODBError, SherlockUpdatePartModelingPropsError +from ansys.sherlock.core.errors import ( + SherlockImportProjectZipArchiveError, + SherlockUpdatePartModelingPropsError, +) ############################################################################### # Launch PySherlock service @@ -57,23 +60,19 @@ sherlock = launcher.launch_sherlock(port=9092) ############################################################################### -# Import ODB++ Archive -# ===================== -# Import the ODB++ archive from the Sherlock tutorial directory. +# Import Tutorial Project +# ======================== +# Import the tutorial project zip 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, + sherlock.project.import_project_zip_archive( project="Test", - cca_name="Card", + category="Demos", + archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")), ) - print("ODB++ archive imported successfully.") -except SherlockImportODBError as e: - print(f"Error importing ODB++ archive: {str(e)}") + print("Tutorial project imported successfully.") +except SherlockImportProjectZipArchiveError as e: + print(f"Error importing project zip archive: {e}") ############################################################################### # Update Part Modeling Properties @@ -82,7 +81,7 @@ try: modeling_props = { - "cca_name": "Card", + "cca_name": "Main Board", "part_enabled": True, "part_min_size": 1, "part_min_size_units": "in", @@ -94,12 +93,12 @@ "part_results_filtered": True, } sherlock.analysis.update_part_modeling_props( - project_name="Test", - modeling_props=modeling_props, + project="Test", + part_modeling_props=modeling_props, ) print("Part modeling properties updated successfully.") except SherlockUpdatePartModelingPropsError as e: - print(f"Error updating part modeling properties: {str(e)}") + print(f"Error updating part modeling properties: {e}") ############################################################################### # Exit Sherlock diff --git a/examples/01-project-configuration/update_parts_list.py b/examples/01-project-configuration/update_parts_list.py index ac6e20b4..74292655 100644 --- a/examples/01-project-configuration/update_parts_list.py +++ b/examples/01-project-configuration/update_parts_list.py @@ -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 @@ -44,7 +44,10 @@ import os from ansys.sherlock.core import launcher -from ansys.sherlock.core.errors import SherlockImportODBError, SherlockUpdatePartsListError +from ansys.sherlock.core.errors import ( + SherlockImportProjectZipArchiveError, + SherlockUpdatePartsListError, +) from ansys.sherlock.core.types.parts_types import ( PartsListSearchDuplicationMode, PartsListSearchMatchingMode, @@ -61,23 +64,19 @@ sherlock = launcher.launch_sherlock(port=9092) ############################################################################### -# Import ODB++ Archive -# ===================== -# Import the ODB++ archive from the Sherlock tutorial directory. +# Import Tutorial Project +# ======================== +# Import the tutorial project zip 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, + sherlock.project.import_project_zip_archive( project="Test", - cca_name="Card", + category="Demos", + archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")), ) - print("ODB++ archive imported successfully.") -except SherlockImportODBError as e: - print(f"Error importing ODB++ archive: {str(e)}") + print("Tutorial project imported successfully.") +except SherlockImportProjectZipArchiveError as e: + print(f"Error importing project zip archive: {e}") ############################################################################### # Update Parts List @@ -86,15 +85,15 @@ try: sherlock.parts.update_parts_list( - project_name="Test", - cca_name="Card", - library_name="Sherlock Part Library", + project="Test", + cca_name="Main Board", + part_library="Sherlock Part Library", matching_mode=PartsListSearchMatchingMode.BOTH, duplication_mode=PartsListSearchDuplicationMode.ERROR, ) print("Parts list updated successfully.") except SherlockUpdatePartsListError as e: - print(f"Error updating parts list: {str(e)}") + print(f"Error updating parts list: {e}") ############################################################################### # Exit Sherlock diff --git a/examples/01-project-configuration/update_parts_list_properties.py b/examples/01-project-configuration/update_parts_list_properties.py index 94e63fa7..a14f9dfc 100644 --- a/examples/01-project-configuration/update_parts_list_properties.py +++ b/examples/01-project-configuration/update_parts_list_properties.py @@ -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 @@ -49,7 +49,7 @@ from ansys.sherlock.core import launcher from ansys.sherlock.core.errors import ( SherlockExportPartsListError, - SherlockImportODBError, + SherlockImportProjectZipArchiveError, SherlockUpdatePartsListPropertiesError, ) @@ -64,23 +64,19 @@ sherlock = launcher.launch_sherlock(port=9092) ############################################################################### -# Import ODB++ Archive -# ===================== -# Import the ODB++ archive from the Sherlock tutorial directory. +# Import Tutorial Project +# ======================== +# Import the tutorial project zip 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, + sherlock.project.import_project_zip_archive( project="Test", - cca_name="Card", + category="Demos", + archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")), ) - print("ODB++ archive imported successfully.") -except SherlockImportODBError as e: - print(f"Error importing ODB++ archive: {str(e)}") + print("Tutorial project imported successfully.") +except SherlockImportProjectZipArchiveError as e: + print(f"Error importing project zip archive: {e}") ############################################################################### # Update Parts List Properties @@ -101,13 +97,13 @@ {"reference_designators": ["U7"], "properties": [{"name": "leadBend", "value": "45"}]}, ] sherlock.parts.update_parts_list_properties( - project_name="Test", - cca_name="Card", - properties=parts_properties, + project="Test", + cca_name="Main Board", + part_properties=parts_properties, ) print("Parts list properties updated successfully.") except SherlockUpdatePartsListPropertiesError as e: - print(f"Error updating parts list properties: {str(e)}") + print(f"Error updating parts list properties: {e}") ############################################################################### # Export Parts List @@ -115,15 +111,15 @@ # Export the parts list for the "Card" of the "Test" project to a CSV file. try: - export_path = os.path.join(os.getcwd(), "exportedPartsList.csv") + export_file = os.path.join(os.getcwd(), "exportedPartsList.csv") sherlock.parts.export_parts_list( - project_name="Test", - cca_name="Card", - file_path=export_path, + project="Test", + cca_name="Main Board", + export_file=export_file, ) - print("Parts list exported successfully to", export_path) + print("Parts list exported successfully to", export_file) except SherlockExportPartsListError as e: - print(f"Error exporting parts list: {str(e)}") + print(f"Error exporting parts list: {e}") ############################################################################### # Exit Sherlock diff --git a/examples/01-project-configuration/update_potting_region.py b/examples/01-project-configuration/update_potting_region.py index e5157c39..9074f1da 100644 --- a/examples/01-project-configuration/update_potting_region.py +++ b/examples/01-project-configuration/update_potting_region.py @@ -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 @@ -43,7 +43,6 @@ # sphinx_gallery_thumbnail_path = './images/update_potting_region_example.png' import os -import time from ansys.sherlock.core import launcher from ansys.sherlock.core.errors import ( @@ -68,22 +67,19 @@ sherlock = launcher.launch_sherlock(port=9092) ############################################################################### -# Import Project Zip Archive -# =========================== -# Import the project zip archive from the Sherlock tutorial directory. +# Import Tutorial Project +# ======================== +# 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_name="Tutorial Project", - project_dir="Demos", - zip_file_path=project_zip_path, + project="Test", + category="Demos", + archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")), ) - print("Project zip archive imported successfully.") + print("Tutorial project imported successfully.") except SherlockImportProjectZipArchiveError as e: - print(f"Error importing project zip archive: {str(e)}") - -time.sleep(10) + print(f"Error importing project zip archive: {e}") ############################################################################### # Add Potting Region @@ -100,7 +96,7 @@ rotation=87.8, ) sherlock.layer.add_potting_region( - project_name="Tutorial Project", + project="Test", potting_regions=[ { "cca_name": "Main Board", @@ -116,7 +112,7 @@ ) print("Potting region added successfully.") except SherlockAddPottingRegionError as e: - print(f"Error adding potting region: {str(e)}") + print(f"Error adding potting region: {e}") ############################################################################### # Update Potting Region @@ -142,13 +138,13 @@ try: update_request = UpdatePottingRegionRequest( - project="Tutorial Project", + project="Test", update_potting_regions=[update_data], ) sherlock.layer.update_potting_region(update_request) print("Potting region updated successfully.") except Exception as e: - print(f"Error updating potting region: {str(e)}") + print(f"Error updating potting region: {e}") ############################################################################### # Exit Sherlock diff --git a/examples/01-project-configuration/update_thermal_maps.py b/examples/01-project-configuration/update_thermal_maps.py index 9b1bed8a..2fc4a729 100644 --- a/examples/01-project-configuration/update_thermal_maps.py +++ b/examples/01-project-configuration/update_thermal_maps.py @@ -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 @@ -42,13 +42,9 @@ # sphinx_gallery_thumbnail_path = './images/update_thermal_maps_example.png' import os -import time from ansys.sherlock.core import launcher -from ansys.sherlock.core.errors import ( - SherlockImportProjectZipArchiveError, - SherlockUpdateThermalMapsError, -) +from ansys.sherlock.core.errors import SherlockImportProjectZipArchiveError from ansys.sherlock.core.types.project_types import ( BoardBounds, ImageBounds, @@ -70,23 +66,19 @@ sherlock = launcher.launch_sherlock(port=9092) ############################################################################### -# Import Project Zip Archive -# ============================ -# Import the project zip archive from the Sherlock tutorial directory. +# Import Tutorial Project +# ======================== +# 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_name="Tutorial Project", - demo_folder="Demos", - file_path=project_zip_path, + project="Test", + category="Demos", + archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")), ) - print("Project zip archive imported successfully.") + print("Tutorial project imported successfully.") except SherlockImportProjectZipArchiveError as e: - print(f"Error importing project zip archive: {str(e)}") - -# Wait for 10 seconds to ensure the project is properly imported -time.sleep(10) + print(f"Error importing project zip archive: {e}") ############################################################################### # Update Thermal Maps @@ -124,7 +116,10 @@ ], } ] - sherlock.project.add_thermal_maps("Tutorial Project", add_thermal_map_files) + sherlock.project.add_thermal_maps( + project="Test", + add_thermal_map_files=add_thermal_map_files, + ) thermal_map_files = [ { @@ -137,11 +132,14 @@ "cca_names": ["Main Board"], }, ] - sherlock.project.update_thermal_maps("Tutorial Project", thermal_map_files) + sherlock.project.update_thermal_maps( + project="Test", + thermal_map_files=thermal_map_files, + ) print("Thermal maps updated successfully.") -except SherlockUpdateThermalMapsError as e: - print(f"Error updating thermal maps: {str(e)}") +except Exception as e: + print(f"Error adding or updating thermal maps") ############################################################################### # Exit Sherlock diff --git a/examples/02-analyses/get_parts_list_analysis_props.py b/examples/02-analyses/get_parts_list_analysis_props.py index a9f8adbb..c02b1d1a 100644 --- a/examples/02-analyses/get_parts_list_analysis_props.py +++ b/examples/02-analyses/get_parts_list_analysis_props.py @@ -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 @@ -44,12 +44,11 @@ # sphinx_gallery_thumbnail_path = './images/sherlock_update_part_list_valid_analysis_example.png' import os -import time from ansys.sherlock.core import launcher from ansys.sherlock.core.errors import ( SherlockGetPartsListValidationAnalysisPropsError, - SherlockImportODBError, + SherlockImportProjectZipArchiveError, SherlockUpdatePartListValidationAnalysisPropsError, ) @@ -61,28 +60,22 @@ VERSION = "242" ANSYS_ROOT = os.getenv("AWP_ROOT" + VERSION) -time.sleep(5) # Allow time for environment setup - sherlock = launcher.launch_sherlock(port=9092) ############################################################################### -# Import ODB++ Archive -# ===================== -# Import the ODB++ archive from the Sherlock tutorial directory. +# Import Tutorial Project +# ======================== +# Import the tutorial project zip 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, + sherlock.project.import_project_zip_archive( project="Test", - cca_name="Card", + category="Demos", + archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")), ) - print("ODB++ archive imported successfully.") -except SherlockImportODBError as e: - print(f"Error importing ODB++ archive: {str(e)}") + print("Tutorial project imported successfully.") +except SherlockImportProjectZipArchiveError as e: + print(f"Error importing project zip archive: {e}") ############################################################################### # Update Part List Validation Analysis Properties @@ -92,7 +85,7 @@ try: update_props = [ { - "cca_name": "Card", + "cca_name": "Main Board", "process_use_avl": True, "process_use_wizard": True, "process_check_confirmed_properties": False, @@ -103,10 +96,13 @@ "avl_require_approved_manufacturer": False, } ] - sherlock.analysis.update_part_list_validation_analysis_props("Test", update_props) + sherlock.analysis.update_part_list_validation_analysis_props( + project="Test", + properties_per_cca=update_props, + ) print("Part list validation analysis properties updated successfully.") except SherlockUpdatePartListValidationAnalysisPropsError as e: - print(f"Error updating part list validation analysis properties: {str(e)}") + print(f"Error updating part list validation analysis properties: {e}") ############################################################################### # Get Part List Validation Analysis Properties @@ -114,11 +110,14 @@ # Retrieve the updated part list validation analysis properties. try: - response = sherlock.analysis.get_parts_list_validation_analysis_props("Test", "Card") + response = sherlock.analysis.get_parts_list_validation_analysis_props( + project="Test", + cca_name="Main Board", + ) print("Retrieved part list validation analysis properties:") - print(str(response)) + print(f"Response: {response}") except SherlockGetPartsListValidationAnalysisPropsError as e: - print(f"Error retrieving part list validation analysis properties: {str(e)}") + print(f"Error retrieving part list validation analysis properties: {e}") ############################################################################### # Exit Sherlock diff --git a/examples/02-analyses/get_random_vibe_inputs_fields.py b/examples/02-analyses/get_random_vibe_inputs_fields.py index 0714e6d0..2a772cb9 100644 --- a/examples/02-analyses/get_random_vibe_inputs_fields.py +++ b/examples/02-analyses/get_random_vibe_inputs_fields.py @@ -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 @@ -44,7 +44,6 @@ from ansys.sherlock.core import launcher -from ansys.sherlock.core.errors import SherlockRunAnalysisError ############################################################################### # Launch PySherlock service @@ -62,8 +61,8 @@ random_vibe_input_fields = sherlock.analysis.get_random_vibe_input_fields() print("Random vibration analysis input fields:") print(random_vibe_input_fields) -except SherlockRunAnalysisError as e: - print(f"Error retrieving random vibration input fields: {str(e)}") +except Exception as e: + print(f"Error retrieving random vibration input fields: {e}") ############################################################################### # Exit Sherlock diff --git a/examples/02-analyses/run_analysis.py b/examples/02-analyses/run_analysis.py index b0a70fa4..11a165eb 100644 --- a/examples/02-analyses/run_analysis.py +++ b/examples/02-analyses/run_analysis.py @@ -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 @@ -45,7 +45,6 @@ # sphinx_gallery_thumbnail_path = './images/sherlock_run_advanced_analysis_example.png' import os -import time from ansys.sherlock.core import launcher from ansys.sherlock.core.errors import ( @@ -67,22 +66,17 @@ ############################################################################### # Import Tutorial Project # ======================== -# Import a tutorial project to run analyses on. +# Import the tutorial project zip archive from the Sherlock tutorial directory. try: sherlock.project.import_project_zip_archive( - "Tutorial Project", - "Demos", - ANSYS_ROOT - + os.path.sep - + "sherlock" - + os.path.sep - + "tutorial" - + os.path.sep - + "Tutorial Project.zip", + 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: {str(e)}") + print(f"Error importing project zip archive: {e}") ############################################################################### # Run Multiple Analyses @@ -92,43 +86,30 @@ try: # Run analyses analysis_types = [ - (RunAnalysisRequestAnalysisType.PART_VALIDATION, [("", [])]), - (RunAnalysisRequestAnalysisType.NATURAL_FREQ, [("", [])]), (RunAnalysisRequestAnalysisType.PTH_FATIQUE, [("Environmental", ["1 - Temp Cycle"])]), - (RunAnalysisRequestAnalysisType.ICT, [("", [])]), ( RunAnalysisRequestAnalysisType.SEMICINDUCTOR_WEAROUT, [("Environmental", ["1 - Temp Cycle"])], ), - ( - RunAnalysisRequestAnalysisType.SOLDER_JOINT_FATIGUE, - [("Environmental", ["1 - Temp Cycle"])], - ), (RunAnalysisRequestAnalysisType.THERMAL_DERATING, [("Environmental", ["1 - Temp Cycle"])]), ( RunAnalysisRequestAnalysisType.COMPONENT_FAILURE_MODE, [("Environmental", ["1 - Temp Cycle"])], ), - (RunAnalysisRequestAnalysisType.HARMONIC_VIBE, [("On The Road", ["5 - Harmonic Vibe"])]), - (RunAnalysisRequestAnalysisType.RANDOM_VIBE, [("On The Road", ["1 - Vibration"])]), - ( - RunAnalysisRequestAnalysisType.MECHANICAL_SHOCK, - [("Environmental", ["2 - Shopping Cart"])], - ), - (RunAnalysisRequestAnalysisType.THERMAL_MECH, [("Environmental", ["1 - Temp Cycle"])]), ] for analysis_type, params in analysis_types: - sherlock.analysis.run_analysis("Tutorial Project", "Main Board", [(analysis_type, params)]) + sherlock.analysis.run_analysis( + project="Test", cca_name="Main Board", analyses=[(analysis_type, params)] + ) except SherlockRunAnalysisError as e: - print(f"Error running analysis: {str(e)}") + print(f"Error running analysis: {e}") ############################################################################### # Exit Sherlock # ============= # Exit the gRPC connection and shut down Sherlock. -time.sleep(5) sherlock.common.exit(True) print("Sherlock gRPC connection closed successfully.") diff --git a/examples/02-analyses/run_harmonic_vibe_strain_map_analysis.py b/examples/02-analyses/run_harmonic_vibe_strain_map_analysis.py index 193fbb12..17c56631 100644 --- a/examples/02-analyses/run_harmonic_vibe_strain_map_analysis.py +++ b/examples/02-analyses/run_harmonic_vibe_strain_map_analysis.py @@ -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 @@ -43,15 +43,15 @@ # sphinx_gallery_thumbnail_path = './images/sherlock_run_strain_map_analysis_example.png' import os -import time -from SherlockModelService_pb2 import RunStrainMapAnalysisRequest +from SherlockAnalysisService_pb2 import RunStrainMapAnalysisRequest from ansys.sherlock.core import launcher from ansys.sherlock.core.errors import ( SherlockAddStrainMapsError, - SherlockImportODBError, + SherlockImportProjectZipArchiveError, SherlockRunStrainMapAnalysisError, + SherlockUpdateHarmonicVibePropsError, ) from ansys.sherlock.core.types.analysis_types import ModelSource from ansys.sherlock.core.types.project_types import StrainMapsFileType @@ -67,42 +67,24 @@ sherlock = launcher.launch_sherlock(port=9092) ############################################################################### -# Import ODB Archive and Strain Maps -# ================================== -# Import a project and add strain maps to the Sherlock project. +# Import Tutorial Project +# ======================== +# Import the tutorial project zip archive from the Sherlock tutorial directory. try: - # Import ODB++ archive into the project - sherlock.project.import_odb_archive( - ANSYS_ROOT - + os.path.sep - + "sherlock" - + os.path.sep - + "tutorial" - + os.path.sep - + "ODB++ Tutorial.tgz", - True, - True, - True, - True, + sherlock.project.import_project_zip_archive( project="Test", - cca_name="Card", + category="Demos", + archive_file=(os.path.join(ANSYS_ROOT, "sherlock", "tutorial", "Tutorial Project.zip")), ) -except SherlockImportODBError as e: - print(f"Error importing ODB archive: {str(e)}") + print("Tutorial project imported successfully.") +except SherlockImportProjectZipArchiveError as e: + print(f"Error importing project zip archive: {e}") try: # Add strain maps to the project - strain_map_path = ( - ANSYS_ROOT - + os.path.sep - + "sherlock" - + os.path.sep - + "tutorial" - + os.path.sep - + "StrainMaps" - + os.path.sep - + "StrainMap.csv" + strain_map_path = os.path.join( + ANSYS_ROOT, "sherlock", "tutorial", "StrainMaps", "StrainMap.csv" ) sherlock.project.add_strain_maps( "Test", @@ -115,12 +97,13 @@ "SolidID", "PCB Strain", "µε", - ["Card"], + ["Main Board"], ) ], ) + print("Strain maps added successfully.") except SherlockAddStrainMapsError as e: - print(f"Error adding strain maps: {str(e)}") + print(f"Error adding strain maps: {e}") ############################################################################### # Update Harmonic Vibration Properties @@ -133,7 +116,7 @@ "Test", [ { - "cca_name": "Card", + "cca_name": "Main Board", "model_source": ModelSource.STRAIN_MAP, "harmonic_vibe_count": 1, "harmonic_vibe_damping": "0.01", @@ -152,8 +135,9 @@ } ], ) -except SherlockRunStrainMapAnalysisError as e: - print(f"Error updating harmonic vibe properties: {str(e)}") + print("Harmonic vibration properties updated successfully.") +except SherlockUpdateHarmonicVibePropsError as e: + print(f"Error updating harmonic vibe properties: {e}") ############################################################################### # Run Strain Map Analysis @@ -166,25 +150,25 @@ analysis_type = analysis_type_enum.HarmonicVibe sherlock.analysis.run_strain_map_analysis( "Test", - "Card", + "Main Board", [ [ analysis_type, [ - ["Phase 1", "Harmonic Event", "TOP", "StrainMap - Top"], - ["Phase 1", "Harmonic Event", "BOTTOM", "StrainMap - Bottom"], + ["On The Road", "5 - Harmonic Vibe", "TOP", "StrainMap - Top"], + ["On The Road", "5 - Harmonic Vibe", "BOTTOM", "StrainMap - Bottom"], ], ] ], ) + print("Strain map analysis completed successfully.") except SherlockRunStrainMapAnalysisError as e: - print(f"Error running strain map analysis: {str(e)}") + print(f"Error running strain map analysis: {e}") ############################################################################### # Exit Sherlock # ============= # Exit the gRPC connection and shut down Sherlock. -time.sleep(5) sherlock.common.exit(True) print("Sherlock gRPC connection closed successfully.")