How do I export a currently shown plot using Python?

Category:
Scripting
Answer

There are two ways of exporting shown plots using python:

1) By using command object ComWr

2) By implementing WriteWMF() method on GraphicBoard

Both of them are exporting current shown plot with the difference that ComWr is a command object that has to be defined and later executed, but it offers more file types for our plots to be exported. On the other hand WriteWMF() is a method but plot will be exported only as wmf- no further file types available.

- The following small Python code example exports the currently shown graphic as .wmf file:

import powerfactory as pf
app = pf.GetApplication()

comWr = app.GetFromStudyCase("ComWr")
comWr.iopt_rd = "wmf"# "bmp" for *.bmp
comWr.iopt_savas = 0 # 0 = Write to path, 1 = Open Save Dialog
comWr.f = "C:\\tmp\plot.wmf"

comWr.Execute()

-Second example will export all available SetVipage pages in activated study case by using WriteWMF

import powerfactory
app=powerfactory.GetApplication()

graphPage=app.GetGraphicsBoard()
VIGraph=graphPage.GetContents('*.SetVipage')[0]

for graph in VIGraph:
graphPage.Show(graph)
file_name=(r'C:\Users\Desktop\Folder' + '\\' +graph.loc_name)
graphPage.WriteWMF(file_name)

Back