April 20, 2019, 11:07:14 AM
Forum Rules: Read This Before Posting

### Topic: Aspen Plus ActiveX automation with Python  (Read 1981 times)

0 Members and 1 Guest are viewing this topic.

#### Miguel

• New Member
• Posts: 5
• Mole Snacks: +2/-0
##### Aspen Plus ActiveX automation with Python
« on: July 30, 2018, 09:05:47 AM »
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: [Select]
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")

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: [Select]
MW = aspen.Tree.FindNode("\\Data\\Properties\\Parameters\\Pure Components")
Did anyone experience this problem? I have tried to encode the string as utf-8 and unicode but it didn't work too.

Miguel

#### Borek

• Mr. pH
• Deity Member
• Posts: 24942
• Mole Snacks: +1636/-395
• Gender:
• I am known to be occasionally wrong.
##### Re: Aspen Plus ActiveX automation with Python
« Reply #1 on: July 30, 2018, 09:13:09 AM »
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.
ChemBuddy chemical calculators - stoichiometry, pH, concentration, buffer preparation, titrations.info, pH-meter.info, PZWT_s1

#### Miguel

• New Member
• Posts: 5
• Mole Snacks: +2/-0
##### Re: Aspen Plus ActiveX automation with Python
« Reply #2 on: July 31, 2018, 04:24:11 AM »
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: [Select]
MW = aspen.Tree.FindNode("\\Data\\Properties\\Parameters\\Pure Components\\REVIEW1\\Input\\VALUE\\MW ACID")
It returns a none object, but I figured out a tricky way to get the value:

Code: [Select]
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

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

Regards!

#### plantes

• Very New Member
• Posts: 1
• Mole Snacks: +0/-0
##### Re: Aspen Plus ActiveX automation with Python
« Reply #3 on: April 17, 2019, 10:36:50 AM »
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?