How do I define only single variables to be exported from a resultfile using Python?


Many commands in PowerFactory store results in a resultfile. The export of a resultfile can be done using the ComRes command, which enables either to export all or just selected variables from the result file. 

To do this via Python, the user needs to automatically assign which variables are to be selected.


The following code gets the export command from the stadycase and prepares it in such way that the data can be exported as a csv file. 

In this example a resultfile of a RMS-Simulation is used and the parameter s:xspeed and s:xmt are exported for the three given Synchronous Generators Gen1, Gen2 and Gen3.

The three result file must not be set (set to None), since it is already defined as pResult. However, the column resultobj enables the user to select a different result file and this way to export the results of different simulation in one go.


comRes = app.GetFromStudyCase("ComRes")

comRes.pResult = elmRes
comRes.iopt_exp = 6 # to export as csv
comRes.f_name = r"C:\\tmp\results.csv" # File Name
comRes.iopt_sep = 1 # to use the system seperator
comRes.iopt_honly = 0 # to export data and not only the header
comRes.iopt_csel = 1 # export only selected variables

resultObject = [None, None, None, None, None, None]
elements = [Gen1, Gen1, Gen2, Gen2, Gen3, Gen3]
variable = ["s:xmt", "s:xspeed","s:xmt", "s:xspeed","s:xmt", "s:xspeed"]

comRes.resultobj = resultObject# Export selected
comRes.element = elements
comRes.variable = variable