STAAD.Pro Help

OS. Set Up Your Coding Environment

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.

Note: Microsoft has an excellent reference on getting started programming in python within Visual Studio Code at https://code.visualstudio.com/docs/python/python-tutorial.
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/.
  1. Download and install Visual Studio Code from https://code.visualstudio.com/
  2. Install a python interpreter. 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.
  3. Launch the Visual Studio Code application.
  4. 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.

    1. Select the Extensions tab (or press <Ctrl+Shift+X>).
    2. Search for the term "python".
    3. Select the Python extension (named ms-python.extension).
    4. 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.
  5. Verify the Python installation.
    1. Open a new terminal window in Visual Studio Code by either:

      selecting Terminal > New Terminal

      or

      press <Ctrl+Shift+'>

    1. 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.
  6. 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.

    1. Open a new terminal window in Visual Studio Code.
    2. Type pip install pywin32 and then press <Enter>. The package is downloaded and installed.
    3. Close the Powershell window.
  7. 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.

    1. Open a new terminal window in Visual Studio Code.
    2. Type pip install comtypes and then press <Enter>. The package is downloaded and installed.
    3. Close the Powershell window.