Upgrading

Version 1.x to version 2.x

Name Space

With development of automation capabilities into other MHI products, there no longer is just one “Automation Library”. Instead, each product will have its own Automation Library, which can be independently installed and updated. As such, the original “Automation Library” has been renamed to the “PSCAD Automation Library”.

Correspondingly, the Python name space has changed. Instead of “mhrc.automation”, the PSCAD Automation Library now resides in the “mhi.pscad” name space. This means any existing scripts will need to be updated to use this new name space.

Additionally, several commands have been renamed. For example, the “launch_pscad()” command has been renamed to simply “launch()”, since it is resides in the “mhi.pscad” name space, it should be clear what application is being launched.

Old Script:

import mhrc.automation

pscad = mhrc.automation.launch_pscad()
pscad.load("workspace.pswx")

New Script:

import mhi.pscad

pscad = mhi.pscad.launch()
pscad.load("workspace.pswx")

Coordinate System

Instead of component positions being specified and returned in pixels, positions now use grid units, which are every 18 pixels.

Old Script:

main.select_components(x1=1425, y1=634, x2=2394, y2=1240)

New Script:

main.select_components(x1=1425//18, y1=634//18, x2=2394//18, y2=1240//18)

Or equivalently:

main.select_components(x1=79, y1=35, x2=133, y2=68)

Deprecated Commands

The original Automation Library communicated with PSCAD using XML fragments. Some automation commands returned these XML fragments directly. A Python script could examine these fragments to extract the desired information.

Since the new communication protocol is no longer based on XML, any commands which returned these XML fragments are deprecated, and will raise a NotImplementedException. The exception message, or an earlier DeprecationWarning message will describe an alternate function to use to obtain the same information.

This version 1 code will no longer work:

vdiv = pscad.project('vdiv')
vdiv.run()
resp = vdiv.get_output()
output_node = resp.find('output')
if output_node is not None:
    output = "".join(output_node.itertext())

Result:

Warning (from warnings module):
  File "...", line ...
DeprecationWarning: This method is deprecated
Traceback (most recent call last):
  ...
NotImplementedError: Use Project.output()

Other command names were simply verbose, or deemed not “Pythonic”, and have been renamed. In these cases, the DeprecationWarning message will provide the new function to use, but the function will continue to function properly. However, deprecated commands may be removed in a future version of the PSCAD Automation Library, so the script should be updated to use the newer functions.

This version 1 code will work, but produces deprecation warnings:

vdiv = pscad.project('vdiv')
vdiv.run()
output = vdiv.get_output_text()

Result:

Warning (from warnings module):
  File "...", line ...
DeprecationWarning: Use Project.output()

Properly updated code:

vdiv = pscad.project('vdiv')
vdiv.run()
output = vdiv.output()