Revision history  [back]

This is how I do it:

Assuming you can run Python programs currently and you want to run from the command line.

I can't post links, so I had to change this to be more complicated. There is a clever way to put the bulky path stuff in the beginning into a library. This should work with PSSE 33 or 34.

Modify with filenames and try and run this code, preferably from one of the Command Line file links provided by PTI with PSSE (in the PSSE34 Folder on the Start Menu):

import _winreg
import sys
import os
# Add the PSS/E directories to our Windows path variable so we can load in the PSS/E Python libraries that are available there


if 'PSSE34' in os.getenv('PATH'):
    print('PSSE 34 detected')
    try:
        pssepath, regtype = _winreg.QueryValueEx(_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\PTI\\PSSE 34\\Product Paths", 0, _winreg.KEY_READ), "PsseInstallPath")
    except WindowsError:
        pssepath, regtype = _winreg.QueryValueEx(_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\\Wow6432Node\\PTI\\PSSE 34\\Product Paths", 0, _winreg.KEY_READ), "PsseInstallPath")
    sys.path.append(os.path.join(pssepath, 'PSSBIN'))
    sys.path.append(os.path.join(pssepath, 'PSSLIB'))
    sys.path.append(os.path.join(pssepath, 'PSSPY27'))
    os.environ['PATH'] += ';' + os.path.join(pssepath, 'PSSBIN')
    os.environ['PATH'] += ';' + os.path.join(pssepath, 'PSSLIB')
    os.environ['PATH'] += ';' + os.path.join(pssepath, 'PSSPY27')
else:
    try:
        pssepath, regtype = _winreg.QueryValueEx(_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\PTI\\PSSE 33\\Product Paths", 0, _winreg.KEY_READ), "PsseInstallPath")
    except WindowsError:
        pssepath, regtype = _winreg.QueryValueEx(_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\\Wow6432Node\\PTI\\PSSE 33\\Product Paths", 0, _winreg.KEY_READ), "PsseInstallPath")
    sys.path.append(os.path.join(pssepath, 'PSSBIN'))
    sys.path.append(os.path.join(pssepath, 'PSSLIB'))
    os.environ['PATH'] += ';' + os.path.join(pssepath, 'PSSBIN')
    os.environ['PATH'] += ';' + os.path.join(pssepath, 'PSSLIB')

import psspy
import redirect

redirect.psse2py()

psspy.psseinit(150000)

case = r'your_save_case.sav'
resp = r'your_resp_file.idv'

psspy.case(case) #load the case
psspy.runrspnsfile(resp) #run an idev 
psspy.asys(0,1,[330]) #build a subsystem
psspy.area_2(0,0,1) #load/gen report on that subsystem

If it works, use the API in the documentation to build your own code.

You will likely get an error if you don't have certain Python packages installed. You will need to install these using PIP. (Google 'pip install'.)

You can also use the Recorder in the GUI to build .py code like you would .idv files.

This is how I do it:

Assuming you can run Python programs currently and you want to run from the command line.

I can't post links, so I had Place this folder in your working folder or in the Python Search Path (ver 33 and 34 support):

^^ This sets up the search path to change this to be more complicated. There is a clever way to put the bulky path stuff in the beginning into a library. This should work with PSSE 33 or 34.include PSSBIN and PSSLIB locations.

Modify with filenames and try and run this code, preferably from one of the Command Line file links provided by PTI with PSSE (in the PSSE34 Folder on the Start Menu):

from psspyenv import _winreg
psspy
from psspyenv import sys
import os
# Addredirect
redirect.psse2py()

psspy.psseinit(150000)

case = r'your_save_case.sav'
resp = r'your_resp_file.idv'

psspy.case(case) #load the PSS/E directories to our Windows path variable so we can load in the PSS/E Python libraries that are available there


if 'PSSE34' in os.getenvcase
psspy.runrspnsfile('PATH'):
    printresp) #run an idev 
psspy.asys('PSSE 34 detected'0,1,[330]) #build a subsystem
psspy.area_2(0,0,1)
    try:
        pssepath, regtype = _winreg.QueryValueEx(_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\PTI\\PSSE 34\\Product Paths", 0, _winreg.KEY_READ), "PsseInstallPath")
    except WindowsError:
        pssepath, regtype = _winreg.QueryValueEx(_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\\Wow6432Node\\PTI\\PSSE 34\\Product Paths", 0, _winreg.KEY_READ), "PsseInstallPath")
    sys.path.append(os.path.join(pssepath, 'PSSBIN'))
    sys.path.append(os.path.join(pssepath, 'PSSLIB'))
    sys.path.append(os.path.join(pssepath, 'PSSPY27'))
    os.environ['PATH'] += ';' + os.path.join(pssepath, 'PSSBIN')
    os.environ['PATH'] += ';' + os.path.join(pssepath, 'PSSLIB')
    os.environ['PATH'] += ';' + os.path.join(pssepath, 'PSSPY27')
else:
    try:
        pssepath, regtype = _winreg.QueryValueEx(_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\PTI\\PSSE 33\\Product Paths", 0, _winreg.KEY_READ), "PsseInstallPath")
    except WindowsError:
        pssepath, regtype = _winreg.QueryValueEx(_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\\Wow6432Node\\PTI\\PSSE 33\\Product Paths", 0, _winreg.KEY_READ), "PsseInstallPath")
    sys.path.append(os.path.join(pssepath, 'PSSBIN'))
    sys.path.append(os.path.join(pssepath, 'PSSLIB'))
    os.environ['PATH'] += ';' + os.path.join(pssepath, 'PSSBIN')
    os.environ['PATH'] += ';' + os.path.join(pssepath, 'PSSLIB')

import psspy
import redirect

redirect.psse2py()

psspy.psseinit(150000)

case = r'your_save_case.sav'
resp = r'your_resp_file.idv'

psspy.case(case) #load the case
psspy.runrspnsfile(resp) #run an idev 
psspy.asys(0,1,[330]) #build a subsystem
psspy.area_2(0,0,1) #load #load/gen report on that subsystem

If it works, use the API in the documentation to build your own code.

You will likely get an error if you don't have certain Python packages installed. You will need to install these using PIP. (Google 'pip install'.)

You can also use the Recorder in the GUI to build .py code like you would .idv files.