In order to program OpenSTAAD
in Python, you will need to set up a development environment.
A develop environment is typically a program that supports writing the code as
well as a suite of tools to make that job easier. While computer code could be
written in any plain text editor, an integrated development environment (IDE) will
make the job much easier and more efficient. For this guide, you will use Microsoft
Visual Studio Code. This is a popular programming editor which is free to use and
supports many different programming languages through a wide array of extensions.
You are free to use any editor or IDE of
your choice, so long as you have the pywin32 extension added. For example, if you are
comfortable with using Visual Studio 2019, you can read about using Python in Visual
Studio at https://docs.microsoft.com/en-us/visualstudio/python/.
This is the python language version you will be using. This
performs the actual operations of your code. You can download Python from
https://www.python.org/downloads/.
Note: It is recommended that you install Python 3.8, which is the
latest version at the time this guide was written.
Launch the Visual Studio Code application.
Install the Python extension in Visual Studio Code.
The extension is used to help you easily write Python code in the editor. It
can also interact with a interpreter to allow you to run and debug the code
from within the editor itself.
Select the
Extensions tab (or press
Ctrl+Shift+X).
Search for the term
python.
Select the Python extension (named
ms-python.extension).
Click
Install.
Note: The Python extension will also later prompt you to install a
linter (used to provide useful feedback and error detection) and IntelliSense
code completion. These are recommended and useful tools for any editor or IDE.
Verify the Python installation.
Open a new terminal window in Visual Studio Code by either:
selecting Terminal > New Terminal
press
Ctrl+Shift+'
Type
py -3 --version and the press
Enter.
The terminal should return with the version of python
you have installed.
Note: If you have multiple versions of Python installed on your
computer, you may need to select the most recent version in the status bar of
the Visual Studio Code program window.
Install pywin32.
This allows COM objects to interact with Python and is required for using OpenSTAAD in Python. You will use
a package management system built into the Python extension to download an
install this.
Open a new terminal window in Visual Studio Code.
Type
pip install pywin32 and then press
Enter.
The package is downloaded and installed.
Close the Powershell window.
Install the comtypes Python library.
This is a lightweight Python COM package based on the ctypes foreign function
library (cyptes is included in Python 2.5 and later). This package makes it
easier to access and implement both custom and dispatch-based COM
interfaces.