AWRDE is a COM automation server and any programming language that can perform as a COM client can be used. This includes Python. With Python you will need to install the win32com.client library.
Installing win32com (pypiwin32)
Note it is recommended that you use Python version 3.7 or later with AWRDE although earlier versions may work.
pip install pypiwin32
This will install the package into your library. Once this is done the type library for AWRDE must be build. This is done by running the makepy.py script.
In a command prompt, perform the following...
cd [python libinstall directory]/\Lib\site-packages/\win32com/\client python makepy.py
When prompted select the "AWR Microwave Office V15 15 (1.0)" entry in the menu. This script will then create a set of definitions that will be loaded automatically when you connect to AWRDE.
Testing your installation
# Simple script to test win32com installation import win32com.client awrde = win32com.client.Dispatch('AWR.MWOffice') # connect to AWRDE, load AWRDE types for model in awrde.Models: print(model.Name)
Connecting to a Specific Version of AWRDE
First, in the AWR Design Environment, you need to go into the VB scripting and run
to get the CLSID of the instance you want to connect to. This will be something like:
Then, from within python, you use:
Note the braces are required.
Connecting with pyawr
The pywin32 package contains everything needed to connect to AWRDE from Python but since Python is not a strongly typed language, editors do not have the information they need to provide advanced functionality such as IntelliSense. To solve this problem, AWR has created an interface layer on top of win32com which add the type information for the AWR COM interface. With this interface, editors such as Visual Studio Code (using the Visual Studio IntelliCode and Pylance plugins), can provide type hints.
The pyawr package is available at: https://github.com/danecollins/pyawr. See the README for instructions on installation.
When using the mwoffice.py API wrapper layer, connecting to AWRDE will be done a little differently. To connect use the CMWOffice class.
import pyawr.mwoffice as mwo awrde = mwo.CMWOffice()
This will create an object of type pyawr.mwoffice.CMWOffice which has type information defined for it.
pyawr also contains some helper functions which we have found quite useful when using python. The include:
- connect() - a simple way to connect to AWRDE
- open_example() - a function to open any of the standard examples in the installer
- vbrange() - a function which returns a VB style index range. For example vbrange(2) returns 1, 2 (vb indexes start at 1 rather than 0)
- as_list() - a function which takes a VB collection and enumerates it into a list
- meas_from_graph() - returns the measurement objects in a graph
- class AwrMeas - returns an object from an MWO measurement including a pandas DataFrame of the data