Page tree
Skip to end of metadata
Go to start of metadata

It is possible to write scripts for AWRDE in something other than Visual Basic such as Python, Perl, C#, etc.  This article describes the setup for Python

AWRDE is a COM automation server and any programming language that can perform as a COM client can be used. This includes most current programming languages such as Python. With Python you will need to install the win32com.client library.  The easiest way to do this is to use pip.

pip install pypiwin32

While this is the minimum setup, if you plan to do significant work in python you want to create the entire type library you will need to run makepy.py. In a command prompt...

cd [python lib directory]/site-packages/win32com/client
python makepy.py

If you run this with the -v option it will indicate the name of the generated python file in case you want to look at it.  These definitions will be loaded automatically when you connect to AWRDE.

Testing your installation

Here is a very simple python program that connects to AWRDE and writes out all the models in the software:

# Simple script to test interface to AWRDE
 
import win32com.client
 
awrde = win32com.client.Dispatch('AWR.MWOffice')  # connect to AWRDE, load AWRDE types
 
# create shorthand variable to access AWRDE constants
awrc = win32com.client.constants
 
# test that type library is loaded
assert awrc.mwEMS_AwrAxiem64 == 2
 
for model in awrde.Models:
	print(model.Name)


Connecting to a Specific Instance of AWRDE

When you use this line:

# Simple script to test interface to AWRDE
import win32com.client
awrde = win32com.client.Dispatch('AWR.MWOffice')  # connect to AWRDE, latest installed  

It will connect to the most recent version of the AWR Design Environment installed, said another way, the version of the last AWR Design Environment Installer run.   

To call a specific version, you will add the major version number such as:

# Simple script to test interface to AWRDE
import win32com.client
awrde = win32com.client.Dispatch('AWR.MWOffice.13.0')  # connect to AWRDE version 13.0

If you have multiple instances of the AWR Design Environment running at the same time, you can follow the following procedure on how to pick which instance to connect. 

First, in the AWR Design Environment, you need to go into the VB scripting and run

 Sub Main
   Debug.Print MWOffice.InstanceCLSID
End Sub
     

to get the CLSID of the instance you want to connect to. This will be something like:

62F49D56-070F-4E6C-8AB9-25845CB94B9A

Then, from within python, you use:

import win32com.client
obj = win32com.client.Dispatch("{CLSID}")


where you replace CLSID with the id you want to use.

For example

import win32com.client
obj2 = win32com.client.Dispatch("{62F49D56-070F-4E6C-8AB9-25845CB94B9A}")


Note the braces are required.