You are on page 1of 2

import powerfactory #importing of pf module

def getKey(custom):
return custom.loc_name

Alpha = 10
Beta = 1

app=powerfactory.GetApplication() # Calling app Appication object


ldf=app.GetFromStudyCase('ComLdf') #Calling ldf Command object (ComLdf)
ldf.Execute() #executing the load flow command

factible = True

Lines=app.GetCalcRelevantObjects('*.ElmLne')

PerdidasP = 0
PerdidasQ = 0

for line in Lines:

PP=line.GetAttribute('m:Ploss:bus2') #get value for the loading


PQ=line.GetAttribute('m:Qloss:bus2') #get value for the loading

PerdidasP+=float(PP)
PerdidasQ+=float(PQ)

if line.GetAttribute('c:loading')>90:
factible = False

buses = app.GetCalcRelevantObjects('N*.ElmTerm')

DistanciaVoltaje = 0

for bus in buses:


bus_v = bus.GetAttribute('m:u')
DistanciaVoltaje+=abs(1-bus_v)
#app.PrintPlain('Voltage on bus ' + str(bus) + ': ' + str(bus_v) + 'pu')

if bus_v>1.05 or bus_v<0.95:
factible = False

Script=app.GetCurrentScript()
Contents=Script.GetContents()
Cubic1=Contents[0]
Cubic1=Contents[1]
bus.AddCopy(Cubic1)
bus.AddCopy(Cubic2)

f_obj = (Alpha*PerdidasP) + (Beta*DistanciaVoltaje)

app.PrintPlain("Perdidas P: "+str(PerdidasP))
app.PrintPlain("Perdidas Q: "+str(PerdidasQ))
app.PrintPlain("Distancia a voltaje ideal: "+str(DistanciaVoltaje))

app.PrintPlain("Funcion objetivo: "+str(f_obj))

if not factible:
app.PrintPlain("NO factible")

Script=app.GetCurrentScript()
Contents=Script.GetContents()
Cubic=Contents[0]

#buses[10].AddCopy(Cubic)

cap = app.GetCalcRelevantObjects('*.ElmShnt')
conectar = buses[10].GetContents('Cubicle*')[0][0]
cap[0].bus1 = conectar

You might also like