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 "Access the WEAP API via python."
Log in to post new messages or reply to existing messages.
Author Message
Mr. Marcel Gaj

Subject: Access the WEAP API via python.   
Posted: 8/7/2013 Viewed: 58565 times
I managed to use the API of WEAP via python:

A tool called win32com.client is needed and is to be installed under windows.

-> http://sourceforge.net/projects/pywin32/

then you need to create the object:

import win32com.client

Hope this is helpful!
Mr. Kasra Keshavarz

Subject: Re: Access the WEAP API via python.   
Posted: 8/3/2015 Viewed: 52195 times
I know this is an old topic but better than creating a new one, I believe.

I downloaded the pywin32 package and installed it successfully, but still unable to use WEAP API. By searching through website I didn't get anything. Adding other APIs e.g. MSExcel,MSWord,.. can be done very simply but I have problem adding WEAP API. Any help will be appreciated.

The error is something like this:

>>> WEAP=win32com.client.Dispatch(“WEAP.WEAPApplication")

Traceback (most recent call last):
File "", line 1, in
File "C:\Python34\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Python34\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python34\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)

Kasra Keshavarz
Mr. Kasra Keshavarz

Subject: Re: Access the WEAP API via python.   
Posted: 8/4/2015 Viewed: 52133 times
Well, After 2 days of search and surfing the internet, I finally found that WEAP does not automatically "register" itself.
For registering manually just open Windows "Command Prompt" as Administrator, Go to WEAP install directory (e.g. C:\Program Files\WEAP) and simply run the following command:

WEAP /regserver

After registering, accessing API trough python is never easier than before.
Eng. Miguel Ruiz

Subject: Re: Access the WEAP API via python.   
Posted: 8/11/2016 Viewed: 47450 times

I want to know if i need close WEAP from python later Calculate and Saving How I can do it?

Thank you

Miguel, R.

Ms. Stephanie Galaitsi

Subject: Re: Access the WEAP API via python.   
Posted: 8/11/2016 Viewed: 47441 times
Dear Miguel,

I'm not sure that I understood your question, but I will direct you to the WEAP Help menu (open up WEAP, and on the ribbon at the top, go to Help/Contents). There, under "Advanced Topics" you will find a detailed section called "Automating WEAP (API)." The subsection "WEAP Application Class" contains several of the commands you may be looking for, including WEAP.Calculate and WEAP.SaveArea.
Mr. Juan Sebastian Ossa Moreno

Subject: Re: Access the WEAP API via python.   
Posted: 11/24/2017 Viewed: 42340 times

Does anyone know how to adapt lines such as the following (in VBS) into Python?

WEAP.Branch("Supply and Resources\River\Chari\Reaches\Below Return Flow Node28").Variables("Streamflow").Value(my_year,my_month)

I am able to use

WEAP.Branch("Supply and Resources\River\Chari\Reaches\Below Return Flow Node28").Variables("Streamflow").Value

However, when i include brackets after the last word Python thinks i am calling a subset of the object, but as the object is a number it throws an error.
Topic "Access the WEAP API via python."