ODTK Programming Environment
Choosing an environment
A question often asked is, "Which language should I use when working with the Ansys Orbit Determination Tool Kit (ODTK®) application?" So it's worth pointing out a few pros and cons of various choices.
- JScript is free and guaranteed to be on all Windows systems. It natively supports COM interfaces.
- MATLAB is not free and must be installed on each computer. COM support is available but a bit awkward to use. It works well with ASCII and binary files and has excellent support for engineering math operations. You can build a GUI using its internal capabilities.
- Perl is free but must be installed on each computer. It does not natively understand COM interfaces, but modules are available that do so. It works well with ASCII and binary files and has reasonable support for engineering math operations. You can build a GUI using Perl/Tk.
- Python is free but must be installed on each computer. It does not natively understand COM interfaces, but modules are available that do so. It works well with ASCII and binary files and has extensive support for engineering math operations.
- VB.NET is not free and must be installed on each computer. It natively supports COM interfaces. You can build a GUI using standard Windows APIs.
- VBScript is free and guaranteed to be on all Windows systems. It natively supports COM interfaces, but is limited to working with ASCII files and has minimal support for engineering math operations.
Language-specific notes
VBScript
The VBScript engine does not release handles to the objects returned by ODTK functions if they are not stored into variables. If your script must shut down the ODTK application and continue running, then you have to assign all returned handles to some variables. For example, Clear() returns a handle to the empty list container:
ODTK.ProductBuilder.DataProducts.clear() ' Anonymous reference is kept
set unused = ODTK.ProductBuilder.DataProducts.clear()
set unused = Nothing ' This releases the reference
Some functions require String Objects, not just the String data type, so use conventions such as
str = new String("string");
when creating strings. For-in loops do not function well; please use iterated for loops.
Perl
All the Perl examples were tested using Perl 5.8.8 from ActiveState (www.activestate.com). They have a free download of the Perl interpreter, and we have had great success using their implementation.
You must use the Win32:OLE module in order to interface with the ODTK application. Include the following at the top of your Perl script:
use Win32::OLE;
When working with file and directory paths on Windows, Perl returns '/' instead of '\'. Use the following or similar code to convert paths before assigning them to the ODTK variable:
$topdir = cwd();
$topdir =~ s/\//\\/g;
Various methods in the ODTK application will return an OLE collection object. To use these from Perl, you must use the Win32::OLE::Enum module. Alternatively (and somewhat cleaner) is the shortcut keyword "in". This appears in some of the examples later on.
Python
All the Python examples were tested using Python 3.4.3.
For insights and requirements on the Python interface with the ODTK application, see the Python Guidance help topic.
The PyWin32 package is required in order to interface with the ODTK application. You must include the following at the top of your Python script:
import win32com.client as w32cWhen concatenating strings and CDispatch variables into strings, you must cast CDispatch variables to strings with str() first.
If the ODTK application is not recognizing Python as a valid scripting language, please initialize Python ActiveX by running pyscript.py found in:
Python\Lib\site-packages\win32comext\axscript\client\MATLAB
Before using MATLAB, please read the MATLAB help topic "External Interfaces | Getting Started with COM ". MATLAB is case sensitive, so you will find that the Set() method will not work but set() will.