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


About WEAP

Home
Why WEAP?
Features
What's New?
Sample Screens
Demonstration
Applications
Publications
History and Credits

Using WEAP
Download
Licensing
User Guide
Tutorial
Videos
Resources

User Forum
Discussions
Members List
Edit Profile

Additional Support
Training
University Courses
Collaboration

About Us
SEI-US Water Resources Program
Please Contact Us


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

User Forum

All Topics | Topic "Access the WEAP API via python."
Log in to post new messages or reply to existing messages.
 
Author Message
Marcel Gaj

Subject: Access the WEAP API via python.   
Posted: 8/7/2013 Viewed: 13242 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
WEAP=win32com.client.Dispatch(“WEAP.WEAPApplication)

Hope this is helpful!
cheers
Marcel
Kasra Keshavarz

Subject: Re: Access the WEAP API via python.   
Posted: 8/3/2015 Viewed: 6879 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)
"


Sincerely,
Kasra Keshavarz
Kasra Keshavarz

Subject: Re: Access the WEAP API via python.   
Posted: 8/4/2015 Viewed: 6820 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.
Miguel Ruiz

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

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

Thank you
Regards,

Miguel, R.


Stephanie Galaitsi

Subject: Re: Access the WEAP API via python.   
Posted: 8/11/2016 Viewed: 2140 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.
Topic "Access the WEAP API via python."