Automation Library: Basics
Automation Library: Basics
Automation Library: Basics
Automation Library
Revision (2.0)Items in blue are compatible with PSCAD 4.6.2
This is a reference used to describe the PSCAD Python function calls that are available in the
Automation Library. This document will be continuously updated as functions are added.
Basics
PSCAD is a highly structure environment. By design the control and function of the software
is organized in a series of access object that are organized in a hierarchy. Each object
provides functionality at an increasing level of detail. To manipulate the details at lower
levels, the strategy is to access individual controllers that are specifically tailored for that
level of detail. Using abstraction as a natural part of the language, these controllers can be
manipulated with relative ease.
This document outlines the controller function starting with the highest level types and
working its way down the lowest and most detailed types. Each controller has relatively few
methods so that they may be easy to use.
System Dependencies
Standard Operating System parameters and functions
This module provides a portable way of using operating system dependent functionality.
(https://docs.python.org/2/library/os.html)
import os
import sys
import logging
import automation.controller
import win32com.client
import shutil
The Automation Controller is used to launch the application or perform other high level
functions. To access the functionality get the controller object through an access method.
The left hand side (LHS) reference will provide access to the controller methods.
controller = automation.controller.Controller()
Application command functions are the top level of commands that operate on the core
functions. There are only a few commands in this set as it is used primarily for starting,
loading and terminating the application. These commands are embedded in the automation
controller module itself.
launch
The application can be launched using the automation controller. In this case we have
instructed the application to silence all dialogue boxes. The object returned is then used to
provide application control from that point forward.
Arguments:
Product = product identity string
Options = command line options
New workspace
This function will create a brand new workspace
new_workspace()
Quit
The application can be shut down using the quit command.
quit()
Arguments:
cl_use_advanced = 'true' enable Certificate licensing false will use dongle
fortran_version = string that defines fortran version to enable
Load
load([r"C:\test\project.pscx"])
project = project("test")
run_all_simulation_sets()
Navigate up
This command will mimic the navigate up command
navigate_up()
Workspace Controller
workspace controller
Get the workspace controller from the application controller
ws = pscad.workspace()
New Project
Creates a new project with the specified name
Arguments:
selection = 1 for project
'name= name of the project
'path' = path to a directory
Example:
create_project("1", "HelloProject", r"C:\test")
This call will create a new project called HelloProject and place it in a folder called test in
the C drive
New Library
Creates a new library with the specified name
Arguments:
selection = 2 for library
'name= name of the library
'path' = path to a directory
Example:
create_project("2", "HelloLib", r"C:\test")
This call will create a new project called HelloLib and place it in a folder called test in the
C drive
Simulation Sets
ws.create_simulation_set("test")
ws.remove_simulation_set("there")
ss = ws.simulation_set("test")
ss.add_tasks("project1", "project2")
ss.remove_tasks("project1", "project2")
ss.run()
pscad.run_all_simulation_sets()
Project Controller
Project Focus
Put project in focus, this is like selecting a project.
focus()
Project Run
This command is used to run a project
run()
Layers enable/disable
You can specify a layer and enable/disable it
set_layer('Harmonic_Impedance', 'enabled')
Get Canvas
Get a handle to any canvas, for example Main
user_canvas('name of canvas')
Project Save
This command will save the project
save()
Project Save As
This command will save the project with a specified name
user_cmp(1701378181)
Arguments:
'library or project' = name of library or project where the component is
'component' = name of the component
Example:
add_component('Master', 'capacitor')
This call will add capacitor from the Master Library to the current canvas
add_wire((54,18), (180,36))
tline(1935965525)
Get Cable
Get a handle to any cable by using the component ID, exactly like getting User Components.
In the example script we are getting a transmission line with the ID = 1935965525
cable(1935965525)
select_components(x1=1425,y1=634,x2=2394,y2=1240)
copy_as_metafile()
copy_as_bitmap()
Clear Selection
This command clears any selected components. This mimics the action of a single click on
the canvas.
clear_selection()
Component command functions
Set the parameters of any component
You can set the parameters of a user component by first determining what the parameter
variable is. Simply open the parameters of the component and click on the field you want to
change; the variable name will appear below. You can modify more than 1 parameter at the
same time by separating them with a comma in the set_parameters call.
You can also view all the parameter symbols of a component by viewing the Properties
set_parameters(R=0.5)
navigate_in()
set_location(20, 20)
Get component Location
This function will get the current location of a component on the canvas.
get_location()
File utility functions
New folder
Create a new folder at a specified path
os.mkdir(r"C:\testing\output_folder")
Move Files
Move files with specific files extensions from a source folder to a destination folder. In the
example snippet, we are moving all files of type .out and .inf
File.move_files(r"C:\testing\project.gf46", r"C:\testing\output_folder",
".out", ".inf")
Word()
New document
This function will add a new document to Word
new_document()
Add text
This function will add the specified text and allow you to change font size and specify
whether or not the text is bold
addPageBreak()
pasteImage()
Dispatch("Excel.Application")
Visible = True
Open a file
This function will load a file into Excel. A full path must be specified
Workbooks.Open(r'C:\test\Harm.csv')
Workbooks(1)
Sheets(1)
Columns(1)
Select()
Add a chart to a specific workbook
This function will use a workbook object and add a chart to it
workbook.Charts.Add()
Change
chart = chart type
workbook.Charts(1)
This is how you change chart types in Excel. A list of types can be found here:
https://msdn.microsoft.com/en-us/library/office/ff837417.aspx
chart.ChartType = win32com.client.constants.xlXYScatter
workbook.Sheets("worksheet name").Activate()