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:

#!python3
import mhrc.automation

...

If more than one Python 3 interpreter is installed, a more specific version identifier may be used, such as #!python3.4 or #!python3.7, 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 the Python 3.x version of IDLE is used.

[1]Since the number sign is also known as a “hash” mark, and the exclamation mark is also known as a “bang”, the combination of the two characters is pronounced “hash-bang”, and usually shorten to “shebang”.

Launch & Run PSCAD

The following script will:

  • launch PSCAD,
  • Tutorial.pswx workspace,
  • run all simulation sets, and
  • finally exit PSCAD
#!python3
import mhrc.automation

pscad = mhrc.automation.launch_pscad()

pscad.load( r"C:\Users\Public\Documents\PSCAD\4.6.3\Examples x64\tutorial\Tutorial.pswx")
pscad.run_all_simulation_sets()

pscad.quit()