Quick Start

Although any text editor which writes plain text files may be used to write python scripts, using an integrated development environment (IDE) will make developing the scripts easier and assist in debugging the scripts. Python 3.x comes bundled with such a tool, which is called IDLE.

IDLE may be started using “Start ➭ All Programs ➭ Python 3.x ➭ IDLE (Python GUI)”, or by right-clicking on an existing *.py, or *.pyw file, and selecting “Edit with IDLE”.

Python Version

The PSCAD Automation Library is written with Python 3.x. While Python 2.x and Python 3.x can co-exist on a computer, the Python 3.x interpreter must be used to execute scripts with this Automation Library.

A shebang [1] line at the top of the file should be used to ensure the correct Python interpreter version is used. It consists of a number sign, followed by an exclamation mark, followed by the interpreter needed to run the script:

#!/usr/bin/env python3
import mhi.pscad

...

If more than one Python 3 interpreter is installed, a more specific version identifier may be used, such as python3.5 or python3.8, to control which particular subversion is executed.

If a script is run from IDLE, the shebang line is treated as a comment line, so take care to ensure a Python 3.x version of IDLE is used.

Launch & Run PSCAD

The following script will:

  • launch PSCAD,

  • Tutorial.pswx workspace,

  • run all simulation sets, and

  • finally exit PSCAD

#!/usr/bin/env python3
import mhi.pscad

pscad = mhi.pscad.launch()

pscad.load("tutorial/Tutorial.pswx", folder=pscad.examples_folder)
pscad.run_all_simulation_sets()

pscad.quit()