Skip to content

Instantly share code, notes, and snippets.

@jmmauricio
Created June 13, 2015 18:41
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save jmmauricio/1198491fa8223572881a to your computer and use it in GitHub Desktop.
Save jmmauricio/1198491fa8223572881a to your computer and use it in GitHub Desktop.
PowerFactory DigSILENT Python Script to load flow, set variables to save, set event, initialize, run and save results to a txt file
import sys
sys.path.append(r"C:\DigSILENT15p1p7\python")
# import PowerFactory module
import powerfactory
# start PowerFactory in engine mode
app = powerfactory.GetApplication()
user = app.GetCurrentUser()
# activate project
project = app.ActivateProject("Nine Bus System")
prj = app.GetActiveProject()
ldf = app.GetFromStudyCase("ComLdf")
ini = app.GetFromStudyCase('ComInc')
sim = app.GetFromStudyCase('ComSim')
Shc_folder = app.GetFromStudyCase('IntEvt');
terminals = app.GetCalcRelevantObjects("*.ElmTerm")
lines = app.GetCalcRelevantObjects("*.ElmTerm")
syms = app.GetCalcRelevantObjects("*.ElmSym")
Shc_folder.CreateObject('EvtSwitch', 'evento de generacion');
EventSet = Shc_folder.GetContents();
evt = EventSet[0];
evt.time =1.0
evt.p_target = syms[1]
ldf.iopt_net = 0
ldf.Execute()
elmres = app.GetFromStudyCase('Results.ElmRes')
for terminal in terminals:
elmres.AddVars(terminal,'m:u','m:phiu','m:fehz')
for sym in syms:
elmres.AddVars(sym,'s:xspeed')
ini.Execute()
sim.Execute()
evt.Delete()
comres = app.GetFromStudyCase('ComRes');
comres.iopt_csel = 0
comres.iopt_tsel = 0
comres.iopt_locn = 2
comres.ciopt_head = 1
comres.pResult=elmres
comres.f_name = r'C:\Users\jmmauricio\hola.txt'
comres.iopt_exp=4
comres.Execute()
@GermanAntonioFuentesTapias

import os
os.environ["PATH"]=r"C:\DIgSILENT\PF 2023_SP5"+os.environ["PATH"]
import sys
sys.path.append(r"C:\DIgSILENT\PF 2023_SP5\Python\3.8")

#IMPORTAR LA APLICACION

try:

import powerfactory as pf


app = pf.GetApplication()


app.Show()   

outputWindow = app.GetOutputWindow()
outputWindow.Print(pf.OutputWindow.MessageType.Plain, "Hello World!")

except Exception as e:

print("Error corregir",e)

Only close powerfactory, If powerfactory is run, Engine mode with Digrcom.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment