The AWRDE API Scripting Guide is written using SAX Basic which is compatible with the 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: Getting Started and Installation document for pyawr installation instructions.
The syntax for importing pyawr is shown here:
First import pyawr.mwoffice into the Python code and give it the alias, mwo.
Linking to AWRDE
Assign pyawr.mwoffice.CMWOffice() class to object variable. Object variable awrde will be used in these examples.
There are three different ways to link to AWRDE
This is the default method and should be used when only one version of AWRDE is installed on the computer. The latest installed version of AWRDE on the computer is opened with this command
2. Version number
If multiple versions of AWRDE are installed on the computer, use the version option as shown:
3. Class ID (CLSID)
If multiple instances of AWRDE are running simultaneously, then a unique identifier for each AWRDE instance is the CLSID number. The syntax for linking to a specific AWRDE instance is shown here:
The CLSID number for the AWRDE instance can be determined from a VBA script. Create a code module using the scripting editor within AWRDE. Copy the following code and run. The CLSID number will be displayed in the scripting editor's immediate window
Project Collection Object
In the API Scripting Guide, most collection objects are found under the Project collection object. For instance the graphs collection object in SAX Baisc would use this syntax:
Project.Graphs #SAX Basic
In Python, the object variable must precede the Project collection object. So, the same command in Python would be:
In this Python example the Schematic 1 is being assigned to the s collection object variable:
SAX Basic Collection Objects
The AWRDE API is strongly written around the VBA compatible SAX Basic 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 SAX Basic, 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 SAX Biasic 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.