WindFarmer SDK
As an alternative to the built-in script editing user interface, the SDK enables you to automate WindFarmer from your preferred development environment (VSCode, Jupyter notebooks, PyCharm etc.), resulting in a more streamlined development process amenable to all professional software development practices.
The SDK enables you to link to and integrate WindFarmer into your existing software and tooling.
Referencing the SDK
The WindFarmer SDK is a set of .NET .dll's that you can reference in your code to allow you to use the same functions available in the WindFarmer scripting interface.
In Python we recommend using the pythonnet library to add the references and access the SDK. For detailed guidance on setting up a Python environment for automating WindFarmer see Python Setup, but if you wish to work with an existing environment use Pip to install pythonnet:
pip install pythonnet
The python SDK class module below imports clr (pythonnet) and uses it to add references to the WindFarmer automation dlls. The SDK class can be used to access the WindFarmer automation tools from your other Python Scripts. Save this as a new file (sdk.py) and import it to other scripts, or see our automation examples repository to see how to install this as a package.
import os
import sys
import clr # the pythonnet library required
class Sdk:
def __init__(self, windfarmer_installation_folder):
""" Initialise a WindFarmer Analyst instance
Args:
windfarmer_installation_folder: path to the windfarmer installation folder
"""
windfarmer_binary_path = os.path.join(windfarmer_installation_folder, "Bin")
sys.path.append(windfarmer_binary_path)
clr.AddReference("System")
clr.AddReference("System.Collections")
clr.AddReference('GH.WindFarmer.API')
clr.AddReference('GH.WindFarmer.Scripting')
clr.AddReference('GH.PlanningTools.Scripting')
import Scripting
sys.path.append(os.path.join(windfarmer_binary_path, 'PythonLibs', 'WindFarmerAPI'))
from PyScripting import PyToolbox
self._Toolbox = PyToolbox()
self._Scripting = Scripting
self._Workbook = Scripting.Workbook
@property
def Scripting(self):
""" The windfarmer scripting library, for object construction
"""
return self._Scripting
@property
def Workbook(self):
""" The workbook
"""
return self._Workbook
@property
def Toolbox(self):
""" The toolbox
"""
return self._Toolbox
You can then import the sdk module into your other scripts, and use it to create a WindFarmer object that exposes the Toolbox, Workbook and Scripting objects required for WindFarmer automation:
# SETUP SDK CONNECTION
import sdk
windfarmer_installation_folder = r'C:\Program Files\DNV\WindFarmer - Analyst 1.5.1.1'
# connect to the SDK
wf = sdk.Sdk(windfarmer_installation_folder)
print(' > SDK is now up and running!')
After constructing the SDK in the Jupyter notebook below, you can now see the same commands you see within the desktop application script editor in the command autocompletion. They are grouped under the Toolbox, Workbook and Scripting objects:
The Toolbox mostly provides methods that perform calculations, change the workbook or perform a computation to return some results.
Tip
Within the Script editor in the WFA GUI the Workbook, Toolbox and all the objects within Scripting are available directly. If you want to use exactly the same python code in both contexts(e.g. to copy-paste from one environment to the other) you can:
Import all the contents of Scripting library into your python script context. This allows you to use EnergyCalculationToUseType.New instead of wf.Scripting.EnergyCalculationToUseType.New
from Scripting import *
- Alias the Workbook and Toolbox to reduce edits in the in-app script
Workbook = wf.Workbook Toolbox = wf.Toolbox
Open a workbook
The SDK runs an invisible version of the WindFarmer desktop application. It works with one Workbook at a time. To perform your first automations with the SDK you can open an existing workbook:
wf.Toolbox.OpenWorkbook(r'C:\Data\MyProject\WindySite.wwx')
Also see other workbook operations
Close your workbook
At the end of you script, or when you are finished with WindFarmer, call NewWorkbook.
wf.Toolbox.NewWorkbook()
This is the best way to close the existing workbook and ensure nothing is left behind in a temporary directory.
Clone the Examples repository
See our automation examples repository to help you get started automating via the SDK.