All Topics |
Topic: “Access the WEAP API via python.”
Author | Message |
---|
Subject: Access the WEAP API via python.
Posted: 8/7/2013 Viewed: 64345 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 |
Subject: Re: Access the WEAP API via python.
Posted: 8/3/2015 Viewed: 57974 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 |
Subject: Re: Access the WEAP API via python.
Posted: 8/4/2015 Viewed: 57912 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. |
Subject: Re: Access the WEAP API via python.
Posted: 8/11/2016 Viewed: 53228 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. |
Subject: Re: Access the WEAP API via python.
Posted: 8/11/2016 Viewed: 53219 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. |
Subject: Re: Access the WEAP API via python.
Posted: 11/24/2017 Viewed: 48118 times
Hello
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. Regards Juan |
Topic: “Access the WEAP API via python.”