Power Script Reference Manual
Power Script Reference Manual
PowerScript V10
Reference Manual
ASPEN PowerScript is a proprietary computer program of Advanced Systems for Power Engineering, Inc. (ASPEN).
The information in this document is subject to change without notice. Advanced Systems for Power Engineering, Inc.
assumes no responsibility for any errors that may appear in this document.
Copyright 1988-2005 Advanced Systems for Power Engineering, Inc. All rights reserved.
This User's Manual may be duplicated by the Licensee for its own use. You can order a new copy by writing to the
address below. Please refer to document OL-PS-2005.
Telephone: (650)347-3997
Fax: (650)347-0233
eMail: [email protected]
Web Site: www.aspeninc.com
Our office hours are from 8:30 a.m. to 5:30 p.m. Pacific time (GMT-8 in the winter, GMT-7 in the summer), Monday
through Friday.
_________________________________________________________________________________
ASPEN OneLiner, ASPEN PowerScript, ASPEN Power Flow, ASPEN Overcurrent Relay Editor, ASPEN
Distance Relay Editor, ASPEN DistriView, ASPEN Batch Short Circuit Module, ASPEN Breaker Rating
Module and ASPEN Relay Database are trademarks of Advanced Systems for Power Engineering, Inc.
2.1 Introduction
In this section you will learn how to edit a script, run it and debug it. You will also see how to turn the script into
a function that you can call directly from the menu bar of OneLiner or Power Flow.
We will use OneLiner as the executable program in this tutorial. The same steps can be used in the Power Flow
Program.
The example script is a very simple per-unit calculator. The script will use the system MVA of the currently open
network as the base MVA. It will also set the base kV to the nominal kV of the currently selected object on the
one-line diagram. The kV base is set to zero if nothing is selected.
Click on Debug button. The script editor will re-appear in which the line of
code where the error occurred is being highlighted in yellow (the last line,
at the very bottom).
Its clear that the divide by zero error was caused by BazeZ=0 which in
turn is caused by the zero value of BaseKV. We will now add some logic
to the script program to prevent this from happening.
6. Select Run | End to stop the program.
8. Select Run | Start to run the new code. Click on Ohm -> PU with blank Base
kV edit box.
A message will appear with a warning:
Click on OK. The main program dialog will re-appear, ready to accept new
input.
9. Click on Done to close the Per Unit calculator program.
Run the dialog designer program by double clicking on its icon. The
dialog editor screen will appear.
5. Click on the Add Text Label button on the Dialog Editor Tool bar. The cursor
pointer will become a cross.
Click once to the right of the BaseMVA edit box.
Select Window | Properties Window command. This will bring up
Properties for Text Label window.
Enter label (must be > 0)
Go back to the Design window. Adjust size and position of various dialog
box components to tidy up the dialog box.
Repeat the process above to create another identical label next to BaseKV
edit box.
Note: You can also use toolbar button or keyboard short-cut Ctrl-R
Select file name perunit1.bas from the list box and click on Open. The
main dialog of per unit program will appear.
Click on Done when you finish using the per unit calculator.
2. Customize user-defined commands.
Select command Tools | User-defined Commands | Setup. A dialog box will
appear.
Enter Menu label and full path name to per-unit calculator script file as
shown in the picture.
Click on OK when done. The Per Unit Calculator command will now be
available in the program menu.
GetEquipment returns the handle of the next piece of network equipment of the given type.
GetRelay returns the handle of the next protective device in a relay group.
GetBusEquipment returns the handle of the next piece of equipment of a given type at a bus.
FindBusByName returns the handle of the bus having a given name and nominal kV.
NextBusByName returns the handle of the next bus in sorted bus list.
NextBusByNumber returns the handle of the next bus in sorted bus list.
GetData returns handle as part of an object data, e.g., the end buses of a line.
A detailed description of these functions is given in Section 4.
The handle is an identification tag. When you provide the object handle as an input to a PowerScript function,
the function will know which object you are referring to.
In addition to handles returned by the functions listed above, there are several pre-defined handles that give
PowerScript access to general system data:
Table 3.1. List of predefined PowerScript handles
Data Code
System data HND_SYS
Power flow case solution HND_PF
Short circuit case solution HND_SC
Parameters listed in table 3.3 with write access can be modified from PowerScript. There are two functions that
help you modify the parameters of an object: PutData and PostData.
Suppose you want to change three parameters of an object. In your program you must call the function
PutData separately for each of the parameters you are changing. PowerScript automatically creates a
temporary object in memory with the updated parameters.
Once you are done modifying the parameters, you must call the function PostData once to validate the object
data and if the data is valid, copy the temporary object to the OneLiner or Power Flow case.
Return value:
1 success
0 failure
Remarks: To simulate a single intermediate fault without auto-sequencing, set both vdFltOpt(13)and
vdFltOpt(14) to zero
Example:
Return value:
>0 equipment type code
0 failure
Remarks: The input requires a valid equipment handle.
Example:
Purpose: Retrieves the handle of the next equipment of a given type that is attached to a bus.
Example:
Return value:
1 success
0 failure
Remarks: To read a parameter of a network object, you must first obtain the handle prior to calling this function. To
read a system parameter, you can use the pre-defined handle HND_SYS. Data type of outputVal must
agree with that of the parameter being read. The parameter ID code and data type are available in table
3.3.
Example:
Purpose: Retrieves handle of the next equipment of given type in the system. If nType is set to TC_PICK, this
function will return the handle of the selected equipment on the one-line diagram. If nType is set to the
equipment code for generators, shunts, loads, generating units, shunt units, load units, lines, series
capacitors, transformers, phase shifters, switch and relay groups, this function will return the handle of
all the objects, one by one, in the order they are stored in the OneLiner or Power Flow case.
Return value:
1 success
-1 already at the end of the list
0 failure
Remarks: Set nHandle to zero to get the first equipment handle. Set nType to TC_PICK if you want to see which
network element was highlighted on the one-line diagram by the user. (If the user has highlight more
than one piece of equipment, only the handle of the first selection is returned.)
Example:
Purpose: Retrieve power flow for a generator, load, shunt, switched shunt, generating unit, load unit, shunt unit,
transmission line, transformer, or phase shifter.
Return value:
1 success
0 failure
Remarks: The size of arrays vdOut1 and vdOut2 must be at least equal to the number of buses connected to the
equipment: 1 for generator, load, shunt, switched shunt, generating unit, load unit, shunt unit; 2 for Line,
2-winding transformer, phase shifter; switch, switch, 3 for 3-winding transformer. For equipment that has
more than one connected bus, the flow results are stored in the following order:
- vdOut1(1), vnOut2(1): flow from equipments Bus1
- vdOut1(2), vnOut2(2): flow from equipments Bus2
- vdOut1(3), vnOut2(3): flow from equipments Bus3
Example:
Purpose: Retrieve current for a generator, load, shunt, switched shunt, generating unit, load unit, shunt unit,
transmission line, transformer, switch, or phase shifter.
Example:
Purpose: Retrieve voltage of a bus, or of connected buses of a line, transformer, switch or phase shifter.
Example:
Purpose: Retrieve pre-fault voltage of a bus, or of connected buses of a line, transformer, switch or phase shifter.
Example:
' Loop through all relays in the database and find their operating times
nRelayCount& = 0
nRelayHnd& = 0
While GetRelay( nPickedHnd, nRelayHnd& ) > 0
nRelayCount = nRelayCount + 1
nType = EquipmentType( nRelayHnd )
If nType = TC_RLYOCG Then nParamID& = OG_sID
If nType = TC_RLYOCP Then nParamID& = OP_sID
If nType = TC_RLYDSG Then nParamID& = DG_sID
If nType = TC_RLYDSP Then nParamID& = DP_sID
If nType = TC_FUSE Then nParamID& = FS_sID
If GetData( nRelayHnd, nParamID, sID$ ) = 0 Then GoTo HasError
If GetRelayTime( nRelayHnd, 1.0, dTime# ) = 0 Then GoTo HasError
Print "Relay " & sID & ": "; Format( dTime, "#0.#0s" )
Wend
Print "Relays in this group = "; nRelayCount
Stop
' Error handling
HasError:
Print "Error: ", ErrorString( )
Stop
Purpose: Computes operating time for a fuse, an overcurrent relay (phase or ground), or a distance relay (phase or
ground).
Return value:
1 success
0 failure
Remarks: All calls to this function must be preceded by a call to ShowFault or PickFault function.
Relay current multiplying factor will be applied to relay current result from simulation before time
calculation.
Example:
' Loop through all relays and find their operating times
nRelayCount& = 0
nRelayHnd& = 0
While GetRelay( nPickedHnd, nRelayHnd& ) > 0
nRelayCount = nRelayCount + 1
nType = EquipmentType( nRelayHnd )
If nType = TC_RLYOCG Then nParamID& = OG_sID
If nType = TC_RLYOCP Then nParamID& = OP_sID
If nType = TC_RLYDSG Then nParamID& = DG_sID
If nType = TC_RLYDSP Then nParamID& = DP_sID
If nType = TC_FUSE Then nParamID& = FS_sID
If GetData( nRelayHnd, nParamID, sID$ ) = 0 Then GoTo HasError
If GetRelayTime( nRelayHnd, 1.0, dTime# ) = 0 Then GoTo HasError
Print "Relay " & sID & ": "; Format( dTime, "#0.#0s" )
Wend
Print "Relays in this group = "; nRelayCount
Stop
' Error handling
HasError:
Print "Error: ", ErrorString( )
Stop
Purpose: Retrieve post fault current for a generator, load, shunt, switched shunt, generating unit, load unit, shunt
unit, transmission line, transformer, switch or phase shifter. You can get the total fault current by calling
this function with the pre-defined handle of short circuit solution, HND_SC.
Example:
Purpose: Retrieves post-fault voltage of a bus, or of connected buses of a line, transformer, switch or phase
shifter.
Example:
Purpose: Retrieves the description of the last error. The result is a string.
HasError:
Print "Error: ", ErrorString( )
Stop
nCount = FaultSelector( nFltIdx, "My Fault Selector", "Please Select One Fault" )
Purpose: Searches for the bus that has a certain name and nominal kV.
Purpose: Get handle of next bus in a bus list which has been sorted by bus name and nominal kV.
Purpose: Gets the handle of next bus in a bus list which has been sorted by bus number.
Purpose: Move output pointer to a specific short circuit simulation case. PickFault() is a simplified version of
ShowFault(). Use ShowFault() instead if you wish to control precisely what will be shown on the one-line
diagram.
Return value:
1 success
0 failure
Remarks: This function must be called before any post fault voltage and current result can be retrieved. All
subsequent calls to GetSCVoltage and GetSCCurrent functions will return result from the picked short
circuit simulation.
Example:
Purpose: Perform data validation and update data for the given equipment in the network database.
Return value:
1 success
0 failure
Remarks:
Example:
Return value:
1 success
0 failure
Remarks: Set nFlag to True to accept all changes in the change file without having to confirm each one separately.
Example:
Return value:
1 success
0 failure
Remarks: Data type of variable newValue must agree with that of the parameter being updated. See Table 3.3 for
a full listing of equipment parameters and their type.
Example:
Return value:
1 success
0 failure
Remarks:
Example:
Dim vnShowRelay(4)
If ShowFault( 1, 0, 4, 0, vnShowRelay ) = 0 Then GoTo HasError
Do
If GetSCCurrent( HND_SC, vdVal1, vdVal2, 4 ) = 0 Then GoTo HasError
Print #1, FaultDescription(); Chr(10); _
" "; _
Format( vdVal1(1), "####0.0"); "@"; Format( vdVal2(1), "#0.0"), Space(5), _
Format( vdVal1(2), "####0.0"); "@"; Format( vdVal2(2), "#0.0"), Space(5), _
Format( vdVal1(3), "####0.0"); "@"; Format( vdVal2(3), "#0.0")
Loop While ShowFault( SF_NEXT, 0, -999, 0, vnShowRelay ) > 0
B
H
BASIC Language Reference 4
Handles 15
Break Point 8
Pre-defined 15
BusPicker 26
C L
Language Reference 4
Change file See ReadChangeFile
D M
Macros 3
Data
access 16
modification 16 N
Debugging 7
NextBusByName 49
Dialog Box Editor 9
NextBusByNumber 50
DoFault 22, 27
DoPF 23, 29
O
E Object Handles See Handles
Equipment Type Code 16
EquipmentType 31 P
ErrorString 45 Parameter Code 16
Example PickFault 22, 51
Fault location 3 PostData 22, 52
Per-Unit Calculator 5 Power Flow Solution 23
Power flow outage studies 3 PrintTTY 53
Power transfer studies 3 PutData 22
F R
FaulSelector 46 ReadChangeFile 54
FindBusByName 47 Reserved keywords 23
FullBusName 48 Running Script as Program Command 13
Functions list 25
S
Script File
T
Tutorial 5
Type Code See Equipment Type Code