AEDT open project example#
This example shows how to use the AEDTCommon
class to launch a new AEDT session in a thread and open an existing AEDT project.
Perform required imports#
Perform the required imports.
[1]:
import sys
import os
import shutil
[2]:
from ansys.aedt.core import generate_unique_folder_name
[3]:
from ansys.aedt.toolkits.common.utils import download_file
from ansys.aedt.toolkits.common.backend.api import AEDTCommon
Initialize temporary folder and project settings#
Initialize a temporary folder to copy the input file into and specify project settings.
[4]:
URL_BASE = "https://raw.githubusercontent.com/ansys/example-data/master/toolkits/common/"
AEDT_PROJECT = "Test.aedt"
URL = os.path.join(URL_BASE, AEDT_PROJECT)
temp_folder = os.path.join(generate_unique_folder_name())
local_project = os.path.join(temp_folder, AEDT_PROJECT)
download_file(URL, local_project)
[4]:
'C:\\Users\\ansys\\AppData\\Local\\Temp\\pyaedt_prj_7N3\\Test.aedt'
Initialize toolkit#
Initialize the toolkit.
[5]:
toolkit = AEDTCommon()
Initialize AEDT#
Launch a new AEDT session in a thread.
[6]:
thread_msg = toolkit.launch_thread(toolkit.launch_aedt)
DEBUG - Starting thread: Toolkit_Thread
DEBUG - Toolkit is not connected to AEDT.
DEBUG - Launching AEDT.
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.11.1.
Wait for the toolkit thread to be idle#
Wait for the toolkit thread to be idle and ready to accept a new task.
[7]:
idle = toolkit.wait_to_be_idle()
if not idle:
print("AEDT not initialized.")
sys.exit()
DEBUG - Toolkit is busy and processing a task.
DEBUG - Toolkit is busy and processing a task.
DEBUG - Toolkit is busy and processing a task.
DEBUG - Toolkit is busy and processing a task.
DEBUG - Toolkit is busy and processing a task.
DEBUG - Toolkit is idle and ready to accept a new task.
Open project#
Open the project.
[8]:
open_msg = toolkit.open_project(local_project)
DEBUG - Toolkit is not connected to AEDT.
DEBUG - Connecting AEDT.
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.11.1.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT WARNING: Argument `specified_version` is deprecated for method `__init__`; use `version` instead.
PyAEDT WARNING: Argument `new_desktop_session` is deprecated for method `__init__`; use `new_desktop` instead.
PyAEDT INFO: Log on console is enabled.
PyAEDT INFO: Log on file C:\Users\ansys\AppData\Local\Temp\pyaedt_ansys_366c563d-bae8-4934-b587-8b0fc1dff4c9.log is enabled.
PyAEDT INFO: Log on AEDT is disabled.
PyAEDT INFO: Debug logger is disabled. PyAEDT methods will not be logged.
PyAEDT INFO: Launching PyAEDT with gRPC plugin.
PyAEDT INFO: Connecting to AEDT session on gRPC port 49806
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
DEBUG - Toolkit is connected to AEDT.
DEBUG - Project C:\Users\ansys\AppData\Local\Temp\pyaedt_prj_7N3\Test.aedt is opened
DEBUG - Project name: Test
INFO - Updating internal properties.
DEBUG - Updating 'project_list' with value ['C:/Users/ansys/AppData/Local/Temp/pyaedt_prj_7N3/Test.aedt']
DEBUG - Updating 'active_project' with value C:/Users/ansys/AppData/Local/Temp/pyaedt_prj_7N3/Test.aedt
DEBUG - Updating 'design_list' with value {'Test': []}
DEBUG - Properties were updated successfully.
PyAEDT INFO: Desktop has been released.
INFO - AEDT is released.
Get toolkit properties#
Get the toolkit properties, which contain the project information.
[9]:
new_properties = toolkit.get_properties()
Connect design#
Connect or create a new design.
[10]:
toolkit.connect_design()
DEBUG - Toolkit is not connected to AEDT.
DEBUG - Connecting AEDT.
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.11.1.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT WARNING: Argument `specified_version` is deprecated for method `__init__`; use `version` instead.
PyAEDT WARNING: Argument `new_desktop_session` is deprecated for method `__init__`; use `new_desktop` instead.
PyAEDT INFO: Log on console is enabled.
PyAEDT INFO: Log on file C:\Users\ansys\AppData\Local\Temp\pyaedt_ansys_366c563d-bae8-4934-b587-8b0fc1dff4c9.log is enabled.
PyAEDT INFO: Log on AEDT is disabled.
PyAEDT INFO: Debug logger is disabled. PyAEDT methods will not be logged.
PyAEDT INFO: Launching PyAEDT with gRPC plugin.
PyAEDT INFO: Connecting to AEDT session on gRPC port 49806
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
DEBUG - Toolkit is connected to AEDT.
PyAEDT WARNING: Argument `designname` is deprecated for method `__init__`; use `design` instead.
PyAEDT WARNING: Argument `projectname` is deprecated for method `__init__`; use `project` instead.
PyAEDT WARNING: Argument `specified_version` is deprecated for method `__init__`; use `version` instead.
PyAEDT WARNING: Argument `new_desktop_session` is deprecated for method `__init__`; use `new_desktop` instead.
PyAEDT INFO: Parsing C:/Users/ansys/AppData/Local/Temp/pyaedt_prj_7N3/Test.aedt.
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.11.1.
PyAEDT INFO: Returning found Desktop session with PID 4616!
PyAEDT INFO: File C:/Users/ansys/AppData/Local/Temp/pyaedt_prj_7N3/Test.aedt correctly loaded. Elapsed time: 0m 0sec
PyAEDT INFO: Project Test set to active.
PyAEDT INFO: Added design 'HFSS_VCZZ5I' of type HFSS.
PyAEDT INFO: Aedt Objects correctly read
PyAEDT INFO: Project Test Saved correctly
DEBUG - Project name: Test
INFO - Updating internal properties.
DEBUG - Updating 'project_list' with value ['C:/Users/ansys/AppData/Local/Temp/pyaedt_prj_7N3/Test.aedt']
DEBUG - Updating 'active_design' with value HFSS_VCZZ5I
DEBUG - Updating 'active_project' with value C:/Users/ansys/AppData/Local/Temp/pyaedt_prj_7N3/Test.aedt
DEBUG - Updating 'design_list' with value {'Test': ['HFSS_VCZZ5I']}
DEBUG - Properties were updated successfully.
INFO - Toolkit is connected to AEDT design.
[10]:
True
Create a box#
Create a box in the design.
[11]:
toolkit.logger.info("Create Box")
box = toolkit.aedtapp.modeler.create_box([10, 10, 10], [20, 20, 20])
box.plot()
INFO - Create Box
PyAEDT INFO: Modeler class has been initialized! Elapsed time: 0m 1sec
PyAEDT INFO: Materials class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Parsing C:/Users/ansys/AppData/Local/Temp/pyaedt_prj_7N3/Test.aedt.
PyAEDT INFO: File C:/Users/ansys/AppData/Local/Temp/pyaedt_prj_7N3/Test.aedt correctly loaded. Elapsed time: 0m 0sec
PyAEDT INFO: aedt file load time 0.015624284744262695
PyAEDT INFO: PostProcessor class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Post class has been initialized! Elapsed time: 0m 0sec
C:\Users\Public\actions-runner\_work\pyaedt-toolkits-common\pyaedt-toolkits-common\.venv\lib\site-packages\pyvista\jupyter\notebook.py:37: UserWarning: Failed to use notebook backend:
No module named 'trame'
Falling back to a static output.
warnings.warn(
[11]:
<ansys.aedt.core.visualization.plot.pyvista.ModelPlotter at 0x1da8e682a30>
Save and release AEDT#
Save and release AEDT.
[12]:
toolkit.release_aedt(True, True)
PyAEDT INFO: Desktop has been released and closed.
INFO - AEDT is released.
[12]:
True
Remove temporary folder#
Remove the temporary folder.
[13]:
shutil.rmtree(temp_folder, ignore_errors=True)