PyAEDT: How to Control the Ansys Electronics Desktop with Python
Hello everyone, Ian from Ozen Engineering here. Today we're going to start our discussion on PyAEDT. This is the Python library that interfaces with the AEDT API. It's really cool because it lets you leverage other libraries such as NumPy, SciPy, and Matplotlib for advanced data processing and visualization. It's a powerful tool for streamlining and automating tasks in electromagnetic, thermal, and mechanical analysis.
Introduction to PyAEDT
PyAEDT is one of the packages of PyAnsys. While there are many different packages to explore, I'll be focusing on PyAEDT. To get started with scripting, open up the help and look at the scripting help PDF. This will be one of your main resources for learning how to script.
Python Environments
We'll be interacting with different Python environments. I won't cover VBScript because I recommend using IronPython instead. If you want to compare how they work, the scripting guide has a useful table showing counterparts between VBScript and IronPython. We'll focus on CPython and PyAEDT.
CPython and IronPython
These two environments are compatible with PyAEDT. IronPython is an implementation of Python that integrates with the .NET framework, allowing scripts to run directly within Ansys products. This guide isn't comprehensive for IronPython, so I recommend checking the documentation on IronPython.net.
Setting Up Your Environment
To get started, check out the PyAnsys documentation on docs.pyansys.com and navigate to the latest version of the PyAEDT documentation. We'll set everything up outside of the Ansys environment.
- Create a folder for your projects.
- Open a terminal window to begin installation.
- Use
pipto install PyAEDT. You can also usecondaif preferred. - Ensure you have the latest version:
pip install update pyAEDT. - Install other basic packages like NumPy and Matplotlib if not already installed.
Using Jupyter Notebooks
I'll be using Jupyter notebooks, which I'm a big fan of. You can download example problems from the PyAnsys website as Jupyter notebooks. Once installed, open it with jupyter notebook in your terminal. Your browser will display your Jupyter notebook interface.
Starting with PyAEDT
Let's get into using PyAEDT:
- Import all required libraries. If imported properly, there should be no issues.
- Set the AEDT version and turn off non-graphical mode to visualize actions.
- Download the example file to a temporary folder.
- Open Maxwell 2D with the default command, setting the project name and version.
- Use
m2d.setActiveDesignto open a design.
Analyzing and Saving Projects
Once a design is open, you can:
- Enable and analyze setups.
- Check if simulations are running with
m2d.areSimulationsRunning. - Plot results, such as flux linkage over time.
- Save the project with
m2d.saveProject. - Release the desktop to free up resources with
m2d.releaseDesktop.
Conclusion
This session went longer than expected, but we'll have more videos covering basic operations and optimizing your workflow. We'll eventually model core loss in significant ways in both 2D and 3D. If you have any questions or topics you want covered, especially regarding PyAnsys or PyAEDT, let me know in the comments below.
Thanks for watching, this has been Ian from Ozen Engineering.
Hello everyone, Ian from Ozen Engineering here. Today we're going to start our discussion on PyAEDT. This is the Python library that interfaces with the AEDT API.
It's really cool because it lets you leverage other libraries such as NumPy or SciPy, Matplotlib, and so on, for advanced data processing and visualization. It's a powerful tool for streamlining and automating tasks in electromagnetic, thermal, and mechanical analysis.
PyAEDT is just one of the packages of PyAnsys. You can get started with scripting by opening up the help and looking at the scripting help PDF. We'll be interacting with different Python environments, specifically CPython and IronPython.
IronPython is an implementation of Python that integrates with the .NET framework, allowing scripts to run directly within Ansys products. We'll talk more about IronPython when we start talking about the script execution environment built into the .NET framework.
To get started, install pyAEDT and ensure you have the latest version using pip: ``` pip install pyAEDT pip install --upgrade pyAEDT ``` If you don't have it already, install other basic packages like numpy, matplotlib, etc. When running Python, I'll be using a Jupyter notebook.
You can download example problems from the PyAnsys website as Jupyter notebooks.
Now, let's import the required packages and start setting up our environment: ```python import pyAEDT # Set the AEDT version, turn non-graphical mode off, and download the example file aedt = pyAEDT.AEDT() aedt.SetVersion("2024R1") aedt.TurnOffNonGraphicalMode() aedt.DownloadExampleFile("ControlProgram.aedt") # Open Maxwell 2D with the default command project_name = "ControlProgram Demo" aedt.StartMaxwell2D(project_name, "2024R1", False, False) ``` This will start a new AEDT session and open the project in a new window.
You can then access the designs in the project and open one using the `m2d.setActiveDesign` method. For more information on the API, search for functions in the API documentation. Our main focus will stay on PyAEDT and PyAnsys.
If you want to check out anything we covered today in more detail, I recommend checking out the PyAnsys documentation on [docs.pyansys.com](http://docs.pyansys.com) and going to the latest version of the PyAEDT documentation.
Remember to release the desktop when you're done to free up system resources and avoid performance and license issues. ```python aedt.ReleaseDesktop() ``` That's it for this one. We'll have just a few more covering basic operations and optimizing your workflow.
We'll eventually be able to extract field information from mesh nodes and model core loss in significant ways in both 2D and 3D. If you have any questions or want me to cover something specific related to PyAnsys or PyADT, let me know in the comments below. Thanks for watching!

