August 21, 2019, 05:38:22 AM
Forum Rules: Read This Before Posting


Topic: Using python and COM to read data from ASPEN plus  (Read 823 times)

0 Members and 1 Guest are viewing this topic.

Offline gary_brown

  • New Member
  • **
  • Posts: 3
  • Mole Snacks: +0/-0
Using python and COM to read data from ASPEN plus
« on: February 14, 2019, 04:26:26 PM »
Can someone please tell me how to list all the components in a stream using COM+Python?

I have this output stream and its path in aspen plus variable explorer is:
aspen.Tree.FindNode("\Data\Streams\COM1\Output\STR_MAIN\MASSFLMX\MIXED")

This stream as 8 components: Water, SO2,CO2, etc as shown in the fig link below:

https://drive.google.com/file/d/1h6_sJL7rttPUbL7XUdcVRdDJiVAWBCoq/view?usp=sharing

How can I list all the components in this stream in python environment?

Thanks,
Gary.
« Last Edit: February 14, 2019, 04:39:59 PM by gary_brown »

Offline Miguel

  • New Member
  • **
  • Posts: 5
  • Mole Snacks: +2/-0
Re: Using python and COM to read data from ASPEN plus
« Reply #1 on: February 17, 2019, 07:38:41 AM »
Hi Gary,

Your aspen.Tree.FindNode("\Data\Streams\COM1\Output\STR_MAIN\MASSFLMX\MIXED") is a comp object with its attributes, such as Name, Elements, Value... You can check if they exist with the function:

comp = aspen.Tree.FindNode("\Data\Streams\COM1\Output\STR_MAIN\MASSFLMX\MIXED")
hasattr(comp, Elements)

This will return True or False. Also you can loop in this attributes:

for obj in comp.Elements:
    if obj.Name == "WATER":
        print(obj.Value)

Good luck with your work!

Offline gary_brown

  • New Member
  • **
  • Posts: 3
  • Mole Snacks: +0/-0
Re: Using python and COM to read data from ASPEN plus
« Reply #2 on: February 18, 2019, 01:11:55 PM »
Hi Miguel, thanks a lot for replying. I was stuck on this issue for a while now.

I did try to check with the function you mentioned. I am getting the following error:

x = aspen.Tree.FindNode("\Data\Streams\COM1\Output\STR_MAIN\MASSFLOW\MIXED")
hasattr(x,Elements)

NameError: name 'Elements' is not defined

Also, you said I can loop in its attributes. But what if I don't know the names of each component in the stream and I would like to list ALL the components in the stream? In your reply, you wrote the following code:

for obj in comp.Elements:
    if obj.Name == "WATER":
        print(obj.Value)


But what if I don't now that "WATER" is in the stream. I am stuck in a problem where I have to list all the names of the components in the stream.

Once again, thanks for replying.

Offline Miguel

  • New Member
  • **
  • Posts: 5
  • Mole Snacks: +2/-0
Re: Using python and COM to read data from ASPEN plus
« Reply #3 on: February 20, 2019, 03:32:09 AM »
You are welcome Gary,

Sorry I did a mistake the second variable of hasattr must be a string:

hasattr(x, 'Elements')

To list the elements try:

for obj in x.Elements:
   print(obj.Name, obj.Value)

Also I suggest you to study Python basics ;)

Regards!

Offline gary_brown

  • New Member
  • **
  • Posts: 3
  • Mole Snacks: +0/-0
Re: Using python and COM to read data from ASPEN plus
« Reply #4 on: February 20, 2019, 12:18:06 PM »
Thanks a lot Miguel. It worked!! Really appreciate it.

Sponsored Links