Summary
Problem
Is it It is possible to write scripts for AWRDE in something other than Visual Basic ?
Version and Product
All Versions
All Products
...
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 Perl or Python. With Python you will need to install the win32com.client extension which is available at: Python Download library. The easiest way to do this is to use pip.
Code Block |
---|
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...
Code Block |
---|
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:
Code Block |
---|
...
| ||
# Simple script to test interface to AWRDE import win32com.client awrde = win32com.client.Dispatch( |
...
'MWOApp.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
First in
The same thing can be done from Perl using Perl's COM support. Here is the Perl code to do the same thing:
#
# MWOPerl.pl
#
use Win32::OLE qw(in with); # make sure to include (in & with)
#
# Create an instance of Microwave office and make it visible
#
my $MWOffice = Win32::OLE->new('MWOApp.MWOffice')
or die "couldnt' create";
$MWOffice->{Visible} = True;
#
# Get a list of models and print them to stdout.
#
my $Models = $MWOffice->Models();
foreach my $Model (in $Models)
{
print $Model->{Name}, "\n";
}
Note that the string "MWOApp.MWOffice" will connect to the latest version of the AWRDE you have installed. You can also use "AWR.MWOffice" to get to the latest version or "AWR.MWOffice.7.5" to connect specifically to version 7.5, "AWR.MWOffice.8.0" to connect specifically to version 8.0, etc.
You can also connect to a specific instance of Microwave Office (if you have more than one running) by connecting to the CLSID instead of to the general "MWOApp.MWOffice"
Code Snippets
First in MWO you need to go into the VB scripting and run
...
62F49D56-070F-4E6C-8AB9-25845CB94B9A
Then, from within python you within python you use:
mport win32com.client obj = win32com.client.Dispatch("{CLSID}")
...
Note the braces are required.