User Guide

PyAEDT works both inside AEDT and as a standalone application. It automatically detects whether it is running in an IronPython or CPython environment and initializes AEDT accordingly. PyAEDT also provides advanced error management.

AEDT can be started from Python in the non-graphical mode using AEDT.

Launch AEDT 2021 R1 in Non-Graphical mode

from pyaedt import Desktop, Circuit
with Desktop(specified_version="2021.1", non_graphical=True, new_desktop_session=True, close_on_exit=True,
             student_version=False):
    circuit = Circuit()
    ...
    # Any error here will be caught by Desktop.
    ...

# Desktop is automatically closed here.

The previous command launches AEDT and initializes a new Circuit design.

Electronics Desktop Launched

The same result can be obtained with the following code:

# Launch the latest installed version of AEDT in graphical mode.

from pyaedt import Circuit
with Circuit(specified_version="2021.1", non_graphical=False) as circuit:
    ...
    # Any error here will be caught by Desktop.
    ...

# Desktop is automatically released here.

Pyaedt can also be launched on a remote machine. To do that, the following conditions are needed:

  1. Pyaedt has to be installed on Client and Server machines

  2. No need to have AEDT installed on client machine

  3. Same Python version has to be used on client and server (CPython 3.6+)

  4. On linux server it allows only to run scripts

Here one example of usage on Windows Server:

# Launch the latest installed version of AEDT in graphical mode.

from pyaedt.common_rpc import pyaedt_server
pyaedt_server()

On Client Side:

# Launch the latest installed version of AEDT in graphical mode.

from pyaedt.common_rpc import pyaedt_client
my_client = pyaedt_client("full_name_of_server")
circuit = my_client.root.circuit(specified_version="2021.2", non_graphical=True)
...
# code like locally
...

Here one example of usage on Linux Server:

# Launch the latest installed version of AEDT in graphical mode.

from pyaedt.common_rpc import pyaedt_server
pyaedt_server()

On Client Side:

# Launch the latest installed version of AEDT in graphical mode.

from pyaedt.common_rpc import pyaedt_client
my_client = pyaedt_client("full_name_of_server")
example_script = ["from pyaedt import Circuit", "circuit="Circuit()", "circuit.save_project(\"project_name\")"]
ansysem = "/path/to/AnsysEMxxx/Linux64"
my_client.root.run_script(example_script, ansysem_path=ansysem)
my_client.root.run_script(example_script, aedt_version="2021.2") #if env variable is registered in the server

As an alternative, the user can upload the script to run to the server and run it.

# Launch the latest installed version of AEDT in graphical mode.

from pyaedt.common_rpc import pyaedt_client, upload
my_client = pyaedt_client("full_name_of_server")
local_script ="path/to/my/local/pyaedt/script.py"
remote_script ="path/to/my/remote/pyaedt/script.py"
upload(local_script, remote_script, "servername")
ansysem = "/path/to/AnsysEMxxx/Linux64"
my_client.root.run_script(remote_script, ansysem_path=ansysem)

Variables

PyAEDT provides a simplified interface for getting and setting variables inside a project or a design. You simply need to initialize a variable as a dictionary key. If you use $ as the prefix for the variable name, a project-wide variable is created.

from pyaedt import Hfss
with Hfss as hfss:
     hfss["dim"] = "1mm"   # design variable
     hfss["$dim"] = "1mm"  # project variable
Variable Management

Modeler

Object-oriented programming is used to create and manage objects in the AEDT 3D and 2D Modelers. You can create an object and change properties using getters and setters.

Create a box, assign variables, and assign materials.

from pyaedt.hfss import Hfss
with Hfss as hfss:
     box = hfss.modeler.primitives.create_box([0, 0, 0], [10, "dim", 10],
                                              "mybox", "aluminum")
     print(box.faces)
     box.material_name = "copper"
     box.color = "Red"
Modeler Object