AEDT simple example#

This example shows how to use the AEDTCommon class to launch a new AEDT session in a thread, create an HFSS design, and create a coaxial.

Perform required imports#

Perform the required imports.

[1]:
import sys
from ansys.aedt.toolkits.common.backend.api import AEDTCommon

Initialize toolkit#

Initialize the toolkit.

[2]:
toolkit = AEDTCommon()

Get toolkit properties#

Get the toolkit properties.

[3]:
properties_from_backend = toolkit.get_properties()

Set properties#

Set non-graphical mode.

[4]:
set_properties = {"non_graphical": True}
flag_set_properties, msg_set_properties = toolkit.set_properties(set_properties)
INFO - Updating internal properties.
DEBUG - Updating 'non_graphical' with value True
DEBUG - Properties were updated successfully.

Initialize AEDT#

Launch a new AEDT session in a thread.

[5]:
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.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT WARNING: Argument `specified_version` is deprecated for method `__init__`; use `version` instead.

Wait for the toolkit thread to be idle#

Wait for the toolkit thread to be idle and ready to accept a new task.

[6]:
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.

Connect design#

Connect or create a new design.

[7]:
toolkit.connect_design("HFSS")
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_d5bc3aba-0a2e-47ac-9f2f-b61e547f1257.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 49964
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: 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 4380!
PyAEDT INFO: Project Project238 has been created.
PyAEDT INFO: Added design 'HFSS_2FGE0G' of type HFSS.
PyAEDT INFO: Aedt Objects correctly read
PyAEDT INFO: Project Project238 Saved correctly
DEBUG - Project name: Project238
INFO - Updating internal properties.
DEBUG - Updating 'project_list' with value ['C:/Users/ansys/Documents/Ansoft/Project238.aedt']
DEBUG - Updating 'active_design' with value HFSS_2FGE0G
DEBUG - Updating 'active_project' with value C:/Users/ansys/Documents/Ansoft/Project238.aedt
DEBUG - Updating 'design_list' with value {'Project238': ['HFSS_2FGE0G']}
DEBUG - Properties were updated successfully.
INFO - Toolkit is connected to AEDT design.
[7]:
True

Get toolkit properties#

Get the toolkit properties, which contain the project information.

[8]:
new_properties = toolkit.get_properties()

Create a coaxial#

Create a coaxial in the design.

[9]:
coax = toolkit.aedtapp.modeler.create_coaxial([0, 0, 0], 1)
PyAEDT INFO: Modeler class has been initialized! Elapsed time: 0m 1sec
PyAEDT INFO: Materials class has been initialized! Elapsed time: 0m 0sec

Release AEDT#

Release AEDT.

[10]:
toolkit.release_aedt(False, False)
PyAEDT INFO: Desktop has been released.
INFO - AEDT is released.
[10]:
True

Export AEDT model#

Export the OBJ files.

[11]:
files = toolkit.export_aedt_model()
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_d5bc3aba-0a2e-47ac-9f2f-b61e547f1257.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 49964
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
DEBUG - Toolkit is connected to 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 4380!
PyAEDT INFO: Project Project238 set to active.
PyAEDT INFO: Aedt Objects correctly read
INFO - Toolkit is connected to AEDT design.
PyAEDT INFO: Project Project238 Saved correctly
PyAEDT INFO: Parsing C:/Users/ansys/Documents/Ansoft/Project238.aedt.
PyAEDT INFO: File C:/Users/ansys/Documents/Ansoft/Project238.aedt correctly loaded. Elapsed time: 0m 0sec
PyAEDT INFO: aedt file load time 0.015674591064453125
PyAEDT INFO: Modeler class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: PostProcessor class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Post class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Desktop has been released.
INFO - AEDT is released.

Release and close AEDT#

Release and close AEDT.

[12]:
toolkit.release_aedt(True, True)
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_d5bc3aba-0a2e-47ac-9f2f-b61e547f1257.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 49964
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
DEBUG - Toolkit is connected to AEDT.
PyAEDT INFO: Desktop has been released and closed.
INFO - AEDT is released.
[12]:
True