Specialty Chemistry Forums > Chemical Engineering Forum

Aspen Plus ActiveX automation with Python

(1/1)

Miguel:
Hello there,

I am writing a python script to automate some simulations with Aspen Plus via its COM functions. But when I want to get access to molecular weights values, I have to write something like this:


--- Code: ---import os
import win32com.client as win32

aspen = win32.Dispatch('Apwn.Document')

aspen.InitFromArchive2(os.path.abspath('Aspen\\Flash.bkp'))

MW = aspen.Tree.FindNode("\\Data\\Properties\\Parameters\\Pure Components\\REVIEW-1\\Input\\VALUE\\MW ACID")
--- End code ---

But FindNode function returns a None object due to Python can handle hyphens as identifiers. At least, it is what  I think because the following code works returning a COMObject FindNode:


--- Code: ---MW = aspen.Tree.FindNode("\\Data\\Properties\\Parameters\\Pure Components")
--- End code ---

Did anyone experience this problem? I have tried to encode the string as utf-8 and unicode but it didn't work too.

Thanks in advance!!
Miguel

Borek:
Never worked with the Aspen/Python combination, but you can easily check if it is the hyphen that is problematic by temporarily changing names of directories.

Miguel:
Thanks Borek,

I was breaking my head trying to solve it in Python, but was easier solving it in Aspen renaming the node. I've noticed, also, that spaces give problems too, so should be renamed as well. In some cases it can't be done or I don't know how, for example:


--- Code: ---MW = aspen.Tree.FindNode("\\Data\\Properties\\Parameters\\Pure Components\\REVIEW1\\Input\\VALUE\\MW ACID")
--- End code ---

It returns a none object, but I figured out a tricky way to get the value:


--- Code: ---MW = aspen.Tree.FindNode("\\Data\\Properties\\Parameters\\Pure Components\\REVIEW1\\Input\\VALUE")

for o in MW.Elements:
if o.Name == "MW ACID":
MW_acid = o.Value
--- End code ---

I think that ActiveX automation is not perfect implemented yet, or was not though for Python.

Regards!

plantes:
Hi,

I encountered the same problem, which also comes up if the path contains "\U" (at least in windows). Approaches that will fix these issues with normales paths will return a NoneType as well (e.g. ```r" "```). How can I change the name of the nodes to make it work?

 

Navigation

[0] Message Index

Go to full version