Skip to content

Instantly share code, notes, and snippets.

@jmmauricio
Created June 13, 2015 18:41
Show Gist options
  • Select an option

  • Save jmmauricio/1198491fa8223572881a to your computer and use it in GitHub Desktop.

Select an option

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()
@Sarah3802

Sarah3802 commented Aug 22, 2023

Copy link
Copy Markdown

Hi Everyone, did anybody know how can i create static generator objects in my project and then need to read date from csv file in order to give every photovoltic (static generator) their power and other properties??

@missto98

Copy link
Copy Markdown

Hello, . I'm trying to implement rms simulation via python code and I ran into a problem. I want to extract the value of a variable at a specific moment in time, but I don't know how to do it. can someone help me please? Regards!

@Sina833

Sina833 commented Sep 24, 2023

Copy link
Copy Markdown

Hi
I want to add a shunt element to a bus. How can I do it?
Thanks.

@ashbravo

Copy link
Copy Markdown

When I close powerfactory, I run the following python script:
import sys sys.path.append( r"C:\Program Files\DIgSILENT\PowerFactory 2022\Python\3.10") if __name__ == "__main__": import powerfactory app = powerfactory.GetApplication() if app is None: raise Exception('getting Powerfactory application failed')

Error reported:
Process finished with exit code -1073741819 (0xC0000005)

Tried many methods to no avail, if you have a similar situation and successfully solved it, or if you have other suggestions, please let me know, thank you for your help, it is greatly appreciated

@GermanAntonioFuentesTapias

Copy link
Copy Markdown

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.

ghost commented Jul 1, 2024

Copy link
Copy Markdown

I have Digsilent 15.1 and I want to extract each line losses in load flow simulation, if python needed, what version and what i need to install, I am new thank you for your help. Oh I also tried using DPL but it always ends up in missing semicolon even if its there, code from chatgpt.

@rizky-r-lab

Copy link
Copy Markdown

@rimmetz17
You could only use python 3.3 which is obsolete. You should upgrade your powerfactory

ghost commented Jul 1, 2024

Copy link
Copy Markdown

@rimmetz17 You could only use python 3.3 which is obsolete. You should upgrade your powerfactory

which version is available for python?

@rizky-r-lab

Copy link
Copy Markdown

For python 3.3 you can download it if you Google it. However, for supporting package (numpy, pandas), it quite difficult to search it.
If you can upgrade the powerfactory, I recommend the latest one (powerfactory 2024) or at least powerfactory 2020 (due to my first time using python for powerfactory)

ghost commented Jul 2, 2024

Copy link
Copy Markdown

I already got pf2021 and currently using python 3.9, but i have trouble "cannot connect to powerfactory application". do you have any reference step by step to follow? i am currently using chatgpt as guide

@rezaasaadi

rezaasaadi commented Jul 2, 2024 via email

Copy link
Copy Markdown

ghost commented Jul 2, 2024

Copy link
Copy Markdown

Managed to get the Ploss data from attribute c:Ploss, does anyone know how to get the active power each line? tried using Pline, Plinu(from chatgpt), P, none of them works

@rizky-r-lab

Copy link
Copy Markdown

You can use m:P:bus1 and m:P:bus2 for balance load flow or m:P1:bus1 and M:P2:bus2 for unbalanced.

For reference, you can search the variable in here, depends on what analysis you are doing.
image

To go there, you go into flexible data tab, in network model manager for each class.

ghost commented Jul 3, 2024

Copy link
Copy Markdown

thank u so much for the replies.

now I am wondering why my calculations are differ from the simulation result. I calculate Ploss using I^2 R, which R replaced by Z (R+XL for <80km line), Z calculation are similar than in simulation "resulting values" in line data (6.8 vs 6.78 ohm), Current are similar (both 85A) since Power are similar (both 21-22 MW), using I^2 Z, simulation differ up to 2x-4x value of calculation.

@rizky-r-lab

Copy link
Copy Markdown

I don't know how the procedure that you are using to calculate Ploss. However, If you only calculate Ploss(active power losses), you should using I^2 R, not I^2 Z.

@hediehrasooli-arch

Copy link
Copy Markdown

Problem description (PowerFactory Python / IntForm / Line labels):

I am trying to automatically change the line (ElmLne) labels in the network diagram (Netzmodell) using Python by modifying the corresponding IntForm (e.g. ElmLne_basic_sym.IntForm).

I can successfully access the object:

...\ElmLne_basic_sym.IntForm

Question:
Where are the line label templates actually stored in PowerFactory (Symbol, IntForm, hidden child objects, or annotation layer), and what is the correct Python way to modify them so the diagram updates?

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