Yin
Yin

Reputation: 21

com_error: (-2147352567, 'Exception occured', (10, 'AspenModeler', 'A string value was expected', None, 0, 0), None)

When I use aspen custom modeller in python, This error occurs. Here is the code:

Application = win32.Dispatch('ACM Application 3700')

ACMP = Application.OpenDocument(os.path.abspath("Distillationcolumn.acmf"))

and the error is

com_error: (-2147352567, 'Exception occured', 
(10, 'AspenModeler', 'A string value was expected', None, 0, 0), None)

Does anyone know what happened? Thanks.

Upvotes: 2

Views: 3012

Answers (1)

Mikael YN
Mikael YN

Reputation: 1

I think I might be able to help. Figuring out this issue was part of my PhD thesis, which is digitally published open-access-for-all here. Please feel free to have a look - the solution to your issue is found in Paper V on page 124. The excerpt providing the solution is as follows (Please note that PyMoC is the nickname I gave the software I developed to handle Aspen module co-simulations through Python):

"An important aspect of saving the user time and effort during co-simulation using APD and PyMoC is the ability to have the algorithm automatically load the modules of which file paths have been provided by the user. However, the win32com package of Python 2.7 cannot do this by default, due to what must be considered a bug in the error handling system of said package. As such, the user needs to perform one modification to the code of the win32com package before using properly PyMoC the first time.

During initialization, PyMoC will invoke the OpenDocument function of the Aspen Plus Dynamics COM object that the algorithm has established. Unless win32com has been modified (either by versions released after the time of writing, or by a local user), this will throw an error, and provide an error code to the user. In order to have PyMoC automatically load the modules, this error code needs to be included in the list of ‘bad context’ errors in the file dynamic.py found in the win32com client installation folder. The installation folder is by default named something to the effect of: “C:/Users/[USERNAME]/Anaconda2/pkgs/pywin32-[...]/Lib/site-packages/win32com/client” (provided Anaconda with Python 2.7 is used as a software suite). The file dynamic. py should be modified by adding the error code to the list called ERRORS_BAD_CONTEXT, beginning on row 38. Following this modification, the automated loading of module files will function as intended, and will save lots of time for the user."

Hope this helps -- best of luck to you!

Upvotes: 0

Related Questions