Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Problem

Is it It is possible to write scripts for AWRDE in something other than Visual Basic ?

Solution

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:

               ## This is a very simple python script that connects to AWRDE and
                ## dumps out the complete list of models                
                ##
win32com.client is required for this script to run.  this is                 ## available from:
                ## http://www.python.net/crew/mhammond/win32/Downloads.html
                ##
                import win32com.client
                
                awrde=win32com.client.Dispatch("MWOApp.MWOffice")
                
                for model in awrde.Models:
                print model.name
                

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

...

Name

Connecting to a Specific Instance of AWRDE

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.