The AWRDE API Scripting Guide is written using Visual Basic for Applications (VBA) syntax and coding style. For Python programming, the scripting guide will still serve as the API reference and for the most part, the AWR specific command syntax will still apply. This document shows how to interpret the AWRDE API Scripting Guide for Python coding.
This document assumes that pyawr library has been installed and that you are using a Python IDE that supports code-completion. Please refer to the AWR Scripting in Python document for pyawr installation instructions.
The syntax for importing pyawr and creating the the awrde object is shown here:
First import pyawr.mwoffice into the Python code and give it the alias, mwo. Then assign pyawr.mwoffice.CMWOffice() class to object variable awrde.
In the API Scripting Guide, most collection objects are found under the Project collection object. For instance the graphs collection object in VBA would use this syntax:
In Python, the object variable must precede the Project collection object. So, the same command in Python would be:
VBA Collection Objects
The AWRDE API is strongly written around the VBA collection of objects style of coding. Python will still use these objects, however there are some Python syntax conventions that take precedence. The list of objects can be found in the AWRDE API Scripting Guide > AWR Design Design Component API > Objects List
VBA uses the For Each looping structure and most examples in the AWRDE API Scripting Guide are written using this construct. Here is an example from the API document for looping through all the schematics in the project and printing their names:
In Python the same functionality can be written in two different ways:
In Method 1, the code is more compact, however inside the for loop, code-completion for AWRDE commands does not work. In Method 2, code-completion inside the for loop does work.
In VBA, and extensively in the API Scripting Guide, the Set command is used to assign a collection object to a variable:
In Python, the syntax is as shown
Note that the string literal for VBA is enclosed double quotation marks. For Python, either single quotation or double quotation marks are acceptable.
Indexing Collection Objects
Indexing associated with collection objects is supported with two different styles. When using parentheses () , the index starts at 1 and when when using square brackets , the index starts at 0. The following two commands both print the name of the first schematic in the project:
Here are examples using both styles for printing the names of all the schematics in the project:
The square bracket indexing styling allows lists to be created with constructs that comply with Python methods of accessing elements within a list or array. For instance, using an index of [-1] references the last schematic in the project
Lists can be created from collection of objects using standard range constructs as shown here:
Function parameters use enumerations. The list of enumerations can be found in AWRDE API Scripting Guide > AWR Design Design Component API > Enumerations List. Enumeration List functions are found directly pyawr.mwoffice module. Shown here is an example of reporting the file type of an existing data file:
Print output: mwDataFileType.mwDFT_SNP
This indicates that the data file type is a Touchstone File
Here is an example of adding a new data file using the enumeration for setting the data file type to 'text'.
The following example shows some basic operations using pyawr to interface with AWRDE. Included are updating global frequencies, updating schematic equation, updating schematic element value, simulating the project, reading graph data, and plotting the data. This example assumes that AWRDE is running and is open to a project labelled pyawr_PlotMeasurementData.emp. This project includes a simple filter structure with S-parameters as the graphed data. Variable C1 will be updated in the example code.
This first section imports pyawr, matplotlib and numpy. Then awrde object is created. Next, the active project name is read and the project name read back is compared against the desired project name.
This section demonstrates creating a frequency array using the numpy linspace function. The frequency array is then used to update global project frequencies.
This section shows how to update an equation located in a schematic as well as updating an element parameter.
In this final section, the project is simulated, measurement data is read from a graph, and then matplotlib is used to plot the data.