First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
1 | initial version |
Try this one. Thanks to 3phaseee.com
def GetNLevelBusList(savfnames,targetbus,levels):
TIES=3 #1=Interior Subsystem, 2=Subsystem Ties, 3=Both
ENTRY=1 #1=Branch in One Direction, 2=Branch in Both Directions
BFLAG=4 #1=In-Service Branches, 2=All Branches, 3=In-Service Branches and Xfmrs, 4=All Branches and Xfmrs, 5=In-Service Xfmrs, 6=All Xfmrs
OWNER=1 #1=Bus Owner, 2=Branch Owner
XFLAG=1 #1=In-Service 3WXfmrs, 2=All 3WXfmrs
DCTIES=6 #6=Both Ends
for i in xrange(len(savfnames)):
psspy.case(savfnames[i])
berr=psspy.busexs(targetbus)
if berr==1:
print 'TARGET BUS {0:d} DOES NOT EXIST IN CASE{1:d} !! ... EXITING'.format(targetbus,i)
if ConSole: PauseConsole()
raise Exception('TARGET BUS {0:d} DOES NOT EXIST IN CASE{1:d} !!'.format(targetbus,i))
numbuses=1
buslist=[targetbus]
SID = 1
for x in xrange(levels):
ierr=psspy.bsys(SID,0,[],0,[],numbuses,buslist,0,[],0,[])
#UPDATE BRANCH,3W, AND DC DATA FROM PSSPY.SYS RESULTS --------------
berr, barray = psspy.abrnint(SID, OWNER, TIES, BFLAG, ENTRY, ['FROMNUMBER','TONUMBER'])
biderr, barrayid = psspy.abrnchar(SID, OWNER, TIES, BFLAG, ENTRY, ['ID'])
xerr, xarray = psspy.atr3int(SID, OWNER, TIES, XFLAG, ENTRY, ['WIND1NUMBER','WIND2NUMBER','WIND3NUMBER'])
xiderr, xarrayid = psspy.atr3char(SID, OWNER, TIES, XFLAG, ENTRY, ['ID'])
dcerr, dcarray = psspy.a2trmdcconvint(SID, DCTIES, 2, 1, ['FROMNUMBER','TONUMBER'])
dciderr, dcarrayid = psspy.a2trmdcconvchar(SID, DCTIES, 2, 1, ['DCNAME'])
#BUILD NEW BUS LIST FOR NEXT LEVEL ---------------------------------
newbuslist=[]
for j in xrange(len(barray[0])):
newbuslist.append(barray[0][j])
newbuslist.append(barray[1][j])
for k in xrange(len(xarray[0])):
newbuslist.append(xarray[0][k])
newbuslist.append(xarray[1][k])
newbuslist.append(xarray[2][k])
for m in xrange(len(dcarray[0])):
newbuslist.append(dcarray[0][m])
newbuslist.append(dcarray[1][m])
newbuslist=list(set(newbuslist))
buslist=newbuslist
numbuses=len(buslist)
buslist.sort()
return buslist