The AWR Design Environment (AWRDE) contains a built-in Scripting Development Environment (SDE) based on Visual Basic for Applications (VBA). Scripting automates tasks by controlling items such as schematics, EM structures, VSS system diagrams, and layout as well as retrieving data from the measurements. Python gives the user an alternate programming language in which to write scripts taking advantage of Python's access to a large body of readily available, open-source libraries. AWRDE has an extensive Application Programming Interface (API) to facilitate scripting and the API commands available with VBA can also be accessed using Python. Unlike the built-in SDE, Python is scripted using an external Integrated Development Environment (IDE) of the user's choosing. The Python executable as well the Python library modules reside outside of AWRDE, giving the user flexibility in configuring the Python environment as desired.
VBA versus Python for AWR Scripting
VBA and Python both have their advantages. Choosing which language to use depends on the user's experience level and the requirements that the script must perform.
Advantages of using VBA within AWRDE
- For users who do not know Python.
- For users that do not know any programming languages, VBA integrated within AWRDE can be quicker to develop a working script.
- Easy to create a user interface (UI).
- Can call the script from a menu pick or toolbar icon within AWRDE.
- Script can be saved within the project.
- AWR has a large body of example scripts. A developed script may already exist, or parts of an existing script can be used as a starting place.
Advantages of using Python
- For users who know Python and do not want to learn VBA.
- Access to Python libraries and utilities not available with AWRDE's implementation of VBA
- high level math functions
- digital signal processing functions
- highly flexible plotting
- Faster compute speed on large data arrays.
- Python as a programming language is growing in popularity and as such, there is a large community in which to get help.
- Analysis in a Jupyter Notebook.
Interfacing Between AWRDE and Python
AWRDE uses the Common Object Model (COM) interface as a means of interacting with external applications. COM is a well established standard for many popular applications. One of these applications is Python through the standard win32com library.
The ability to script AWRDE functions using Python has been available for quite some time. With this method, the win32com module is imported directly into the Python script. One disadvantage of this approach is the lack of many convenience items such as code-completion.
An alternate approach for interfacing between Python and AWRDE is by means of the pyawr libary. The pyawr library incorporates win32com and adds AWR specific API functionality. Some of the features that pyawr provide include:
- Code-completion showing lists of API methods and variables associated with a particular API function
- Code-completion description and tips for the methods and variables
- Vector and array indexing that complies with Python coding conventions
- Descriptive error messages
The following is an example showing code-completion that highlights the list of variables and methods associated with the Project.Schematics function. Description associated with the Paste method is also shown
The pyawr library is installed using standard Python package installers such as pip. Once installed, the pyawr module is imported into the Python code similar to other commonly used Python modules. Unlike built-in VBA scripts, Python scripts are developed and executed from within an external IDE that supports code-completion. Some examples of IDE's that support code-completion with pyawr are Visual Studio Code (VS Code), PyCharm, and Spyder, however this list is not exhaustive.
Before installing the pyawr library, there are a number of required programs and libraries that need to be installed first.
Python and pip
Python 3.7 or later must be already installed. Python installer can either be downloaded from Python Org or from a distribution package such as Anaconda. The instructions here will follow using Python Org as the Python installation where pip is the primary means of installing individual modules.
Once Python is installed, you will need to add <Python install directory> and <Python install directory>/Scripts to the Windows path Environmental Variables
To verify Python and pip are installed, in a command window type
If during a subsequent module installation process, a message is given to upgrade pip, use this command
python -m pip install -upgrade pip
Note when using the Anaconda distribution package:
If the above commands are not recognized, then you will need to disable Python application execution aliasing
In Windows, Start > Settings > Apps > Apps & features
Click on App execution aliases
Set python.exe and python3.exe to the off position
There are several IDEs that support code-completion and you can use your preferred IDE if you would like. For users who do not currently use a particular IDE, Visual Studio Code is the recommended IDE, however PyCharm and Spyder are IDEs that have been verified to work with pyawr and code-completion. The following are instructions for installing and configuring for code-completion for VS Code, PyCharm and Spyder
- Download from https://code.visualstudio.com, then install
- Install Python extension from within VS Code: File > Preferences > Extensions, search for Python extension for Visual Studio Code and click Install
- In VS Code, File > Preferences >Settings > Extensions > Python then scroll to Default Interpreter Path and type Python into the entry area
Pylance with VS Code is not recommended when using pyawr. If installed, please uninstall from File > Preferences > Extensions and search for Pylance
If the Anaconda distribution package was used to install Python, open the Anaconda prompt from the Windows Start Menu > Anaconda. In the Anaconda prompt window, type code
Download PyCharm from https://www.jetbrains.com/pycharm and install
Python is automatically recognized and there are no additional settings required to enable code-completion
- Download Spyder from https://www.spyder-ide.org and install
- In a command window, type pip install spyder-kernels
- In Spyder, Tools > Preferences > Completion and linting > Completion tab, check Enable code completion, Show completion details, and Show completions on the fly
- In Spyder, Tools > Preferences > Completion and linting> Advanced tab, uncheck Enable Kite
Other Required Modules
Please install the following libraries:
numpy math functions library:
In a command window, type pip install numpy
scipy advanced math functions library:
In a command window, type pip install scipy
matplotlib plotting functions library:
In a command window, type pip install matplotlib
In a command window, type pip install -U pytest
pandas data analysis library:
In a command window, type pip install pandas
In a command window, type pip install pywin32
Successful installation of these libraries can be verified by typing pip list in a command window
pyawr Installation Procedure
First install win32com and configure it for the AWR Design Environment using this procedure:
- In a command window, type pip install pypiwin32
- cd to <python install directory>/Lib/site-packages/win32com/client
- type python makepy.py
- In the Select Library dialog box, select the AWR Design Environment that corresponds with the AWRDE version you are using
Next, download and install the pyawr library:
- Go to https://github.com/danecollins/pyawr
- Click Code > Download ZIP
- Extract the zip file
- In a command window, cd to <zip file install directory>/pyawr-master/pyawr-master
- Type pip install . (note the dot at the end of this command)
Verify pyawr was successfully installed using the pip list command
Example Python Script to Verify pyawr
Copy and paste the following into the Python editor
Open AWRDE and then open the built-in example LPF_Lumped.emp
Run the Python script
In the Python output terminal, the text output should be: LPF