How to use Python in unattended mode (prior to 2016 known as engine mode) to work with PowerFactory?

Category:
Scripting
Answer

Coding directly in Python Shell is quite similar as writing a Python script in PowerFactory. Only difference is that you have to append the system path so that Python would be able to find powerfactory module (import powerfactory as pf). Also methods Show() and Hide() reserved for the objects of the application class can be helpful while working in unintended Engine Mode with Python.

Open Python Shell and try the following code. Simple code is just activating all available projects.

import sys
sys.path.append(r"C:\Program Files\DIgSILENT\PowerFactory 2018 SP3\Python\3.6")
import powerfactory as pf
app=pf.GetApplicationExt()
app.Show()
user=app.GetCurrentUser()
project=user.GetContents('*.IntPrj')[0]
project.Activate()

When having more than one user in PowerFactory, the line 4 should be changed to:

app=pf.GetApplicationExt('User')

where User is the PowerFactory user name.

Back