Welcome to WEAP's Website WEAP
WEAP is an initiative of the Stockholm Environment Institute.

About WEAP

What's New?
Sample Screens
History and Credits

Using WEAP
User Guide
Videos (YouTube)

User Forum
Members List
Edit Profile

Additional Support
University Courses

About Us
SEI-US Water Resources Program
Please Contact Us

Interested in Energy?
Read about LEAP: SEI's software for energy planning.

Link WEAP and LEAP for combined Water-Energy planning.
Watch a video demo!

User Forum

All Topics | Topic "Multiple runs of model with variable variations"
Log in to post new messages or reply to existing messages.
Author Message
Mr. Gonzalo Cortes

Subject: Multiple runs of model with variable variations   
Posted: 3/4/2011 Viewed: 44019 times
Hi all, I have been using WEAP for almost a year now, and we are performing uncertainty analysis in different models, one of them WEAP, for a high elevation Andean watershed. I know there is a scripting possibility with the new version of WEAP, has anybody already experimented with automatic iterations for one model and automatic variations of a certain variable ?

For example, I would like to have the model output for +-5% variations of soil conductivity, any heads up on a script that has already done that ?

Gonzalo Cortes
Mr. Jack Sieber

Subject: Re: Multiple runs of model with variable variations   
Posted: 3/4/2011 Viewed: 44012 times
Here's a very simple script that demonstrates running a model with varying values of a data variable. Save these lines to a file with a .VBS extension, e.g., Simple.vbs, and double click the file to run it.

' Run WEAP as a COM Automation Server
' Do a sensitivity analysis on the Supply Measures scenario to the population growth rate of South City
' Vary the population growth for South City from 0 to 5%, saving groundwater storage results for each run in c:\GWn.csv

Set WEAP = CreateObject("WEAP.WEAPApplication")

WEAP.Verbose = 1 ' 0 = no dialogs, 1 = errors only, 2 = questions & errors, 3 = warnings, questions & errors, 4 = all dialogs
WEAP.Logfile = WEAP.Directory + "WeapErrors.txt" ' log all errors and warnings to this text file

WEAP.ActiveArea = "Weaping River Basin"
WEAP.ActiveScenario = "Supply Measures"

FOR GrowthRate = 0 to 5

WEAP.Branch("\Demand Sites\South City").Variables("Annual Activity Level").Expression = "Growth(" + FormatNumber(GrowthRate, 0) + "%)"

CALL WEAP.LoadFavorite("Groundwater Storage") ' This will calculate first

IF WEAP.Status = FALSE THEN ' If the user cancels the calculations, exit the FOR loop
CALL WEAP.ExportResults("c:\GW" + FormatNumber(GrowthRate, 0) + ".csv", FALSE, TRUE) ' save these results to a CSV file


' WEAP will close automatically when the script is done, and the changes will NOT be saved to the area
Mr. Gonzalo Cortes

Subject: Re: Multiple runs of model with variable variations   
Posted: 3/4/2011 Viewed: 43993 times
Thanks! I have tried to perform the sensitivity analysis using key assumptions, but I keep getting errors such as "Object doesn´t support..."

The error is displaye for this line and its modifications

WEAP.Branch("Key Assumptions").Expression

Is there a special way to modify key assumptions using scripting ?

Mr. Jack Sieber

Subject: Re: Multiple runs of model with variable variations   
Posted: 3/4/2011 Viewed: 43990 times
You cannot put an expression on the branch \Key Assumption itself. Instead, right click on the Key Assumption branch and create new branches, then put the expressions there. You can also create folders of branches (like in the Weaping River Basin example) under Key Assumptions--just right click on a new branch to create a branch underneath it.

Mr. Eric Olson

Subject: Re: Multiple runs of model with variable variations   
Posted: 10/2/2013 Viewed: 35558 times

Until recently, I've successfully used a VBScript, based on the one posted above. However, I recently received a new computer that has the 64-bit version of Windows 7 Professional installed, and the VBScript no longer works. I'm receiving the following dialog:

"Error: ActiveX component can't create object: 'WEAP.WEAPApplication'
Code: 800A01AD
Source: Microsoft VBScript runtime error"

Searching online suggests there may be a problem with registering dlls. I've tried this, but still haven't been able to get the VBScript to run, so any suggestions would be appreciated.

Thank you,

Eric Olson
Mr. Jack Sieber

Subject: Re: Multiple runs of model with variable variations   
Posted: 10/3/2013 Viewed: 35556 times
Here is how you can manually "register" WEAP. Make sure WEAP is not running. Right click on the Windows "Command Prompt" program and choose "Run as admin". In the command window, go to WEAP folder (e.g., cd C:\Program Files (x86)\WEAP ) and run:

WEAP /regserver

Nothing visible will happen when you do this (you will not see WEAP start), but it should add the correct entries to the Windows Registry to allow you to run WEAP from a script.


Mr. Eric Olson

Subject: Re: Multiple runs of model with variable variations   
Posted: 10/3/2013 Viewed: 35547 times
Thank you, Jack. After registering WEAP, the VBScript is running again.

Thanks again,

Topic "Multiple runs of model with variable variations"