Automating WEAP (API)

WEAP can act as a standard "COM Automation Server," meaning that other programs (e.g., Excel via VBA), programming languages (e.g., Visual Basic, C) or scripts (e.g., VB script, JavaScript, Perl, Python) can control WEAP directly--changing data values, calculating results, and exporting them to text files or Excel spreadsheets. This can be enormously powerful. For example, you could write a 10-line script that would run WEAP calculations 100 times, each time with a different value of an input assumption, and output the results to Excel for later analysis.  WEAP can also call scripts directly (from the Call function in an expression, or from the Advanced, Scripting menu item), and these scripts can use the WEAP API.

The WEAP Application Programming Interface (API) consists of several "classes," each with their own "properties" and "methods." Properties are values that can be inspected or changed, whereas methods are functions that do something.

The following classes are defined:

WEAPApplication: top-level properties and methods, including access to all other classes

WEAPArea: a WEAP Area (dataset)
WEAPAreas
: collection of all WEAP Areas

WEAPScenario: a WEAP Scenario in the active area
WEAPScenarios
: collection of all Scenarios in the active area

WEAPBranch: a specific Branch on the data tree (e.g., \Demand Sites\South City )
WEAPBranches
: collection of all child Branches for a specified Branch (e.g., Branch("\Demand Sites").Children )

WEAPVariable: a Variable for a given Branch (e.g., Consumption for Branch \Demand Sites\South City)
WEAPVariables
: collection of all Variables for a single Branch (e.g., all variables for \Demand Sites\South City )

WEAPVersion: a named version of the active area
WEAPVersions
: collection of all Versions in the active area

Each class is discussed below, followed by tips on exploring the API and an example.

WEAP has its own built-in script editor that can be used to edit, interactively debug and run scripts that automate WEAP using its API.  WEAP uses Microsoft's Windows Script (aka ActiveScript) technology which directly supports scripts written in VBScript and JScript (JavaScript).  VBScript and JScript come with Windows and are always available, whereas other scripting languages, such Perl, Python, Ruby and PHP, must be installed by you on your computer before you can use them in WEAP.

Some other web-based resources you may find useful:

Windows Script Information
VBScript tutorial

VBScript reference guide

JScript reference guide

Free versions of Python, Perl, PHP and Ruby