It has been so long time not to update this blog. And now I'm posting how to access stream component fraction, component molar flowrate and mass flowrate.
Here is the VBA example
Option Explicit
Public hyApp As HYSYS.Application
Public simCase As SimulationCase
Public pStream As ProcessStream
Public Sub StartHYSYS()
Dim filename As String
Dim ITEM As Integer
Dim Compositions As Variant
' HYSYS CUSTOMATION THROUGH EXCEL TO ACCESS STREAM COMPONENTS
' LOADING HYSYS SIMULATION FILE
Set hyApp = CreateObject("HYSYS.Application")
hyApp.Visible = True
Set simCase = hyApp.ActiveDocument
If simCase Is Nothing Then
filename = Worksheets("HYSYS").Range("C4").Text
If filename <> "False" And simCase Is Nothing Then
Set simCase = GetObject(filename, "HYSYS.SimulationCase")
simCase.Visible = True
End If
End If
' READ DATA FROM EXCEL TO "STREAM 1"
Set pStream = simCase.Flowsheet.MaterialStreams.ITEM("STREAM 1")
Compositions = pStream.ComponentMolarFractionValue
For ITEM = 0 To 11 'collect composition data as variant
Compositions(ITEM) = Worksheets("HYSYS").Range("D" & ITEM + 7).Value
Next ITEM
' apply composition data
pStream.ComponentMolarFraction.Values = Compositions
' WRITE COMPOSITION DATA FROM HYSYS TO EXCEL FROM "STREAM 3"
Set pStream = simCase.Flowsheet.MaterialStreams.ITEM("STREAM 3")
For ITEM = 0 To 11 ' number of components are 12
' component molar fraction
Worksheets("HYSYS").Range("E" & ITEM + 7).Value = pStream.ComponentMolarFraction(ITEM)
' component mass flowrate
Worksheets("HYSYS").Range("F" & ITEM + 7).Value = pStream.ComponentMassFlow(ITEM)
' component molar fraction
Worksheets("HYSYS").Range("G" & ITEM + 7).Value = pStream.ComponentMolarFlow(ITEM)
Next ITEM
' FINISH
End Sub
Spreadsheet is look like this figure
Please note, hysys file source is located in Cell C4, refer to following code
filename = Worksheets("HYSYS").Range("C4").Text
Hysys stream is configured as following figure
Hope that helps. Any thought? Please feel free to comment.
hysys simulation
,
hysys training
,
hysys tutorial
,
molar fraction
Subscribe to:
Post Comments (Atom)
Awesome post mate,
ReplyDeleteJust checking - do you need a "Next ITEM"
Before the "Finish" line?
Cheers,
Tristan
Tristan,
ReplyDelete"Next item" should be in the next line. And yes, we need this command.
Hi, I would like to ask you if it's possible to change some equipment specs (example: outlet temperature or reboiler duty of a tower)from excel?? Can you make a post with an example? Thanks a lot, your blog is very helpful.
ReplyDeleteHi Jorge,
ReplyDeleteYes, it is posible to change equipment spec. I'll show you how to change it. And for the example is column operation. Please wait, I'm preparing it.
Many thank for visiting my blog.
Hi,
ReplyDeletethis link s examples are very useful. I am trying to get my code to run correctly but I am having problem with the propriety method. I am trying to activate some of the functions in preferences on VBA but still not working.
I am getting error 438
Can you please help?
Regards
Mayembe
Hi Mayembe,
ReplyDeleteI've opened your code and your hysys file. unfortunately i couldn't open your hysys file. It seems that you're using latest version of aspen hysys.
Thus, i assumed that you are generating hysys file as same as mine.
I checked your VBA code, and I also faces the same problem. "Object does not support this proprity or method." I clicked debug, and I see that this following code is not working.
"Set pStream = simCase.Flowsheet.MaterialStream.ITEM("STREAM1")"
This may you're facing also, I assume. If it is, your code is not correctly defined, since there is no stream "STREAM1" on hysys file, but "STREAM 1". So, stream name doesn't exist on your hysys file. That's why you have that error message.
Hope that helps.
Alex
Great post, I have found it really helpful.
ReplyDeleteMay I ask, how do you select the input for a hysys simulation from a row of data?
In your example the data is in columns and that works on my simulation but due to the vast amount of data I am working with I need to display them in rows.
Would be nice to hear back from you.
Many Thanks
Reggie
Have you tried this coding method in Hysys 10? I am having trouble getting information out in 10.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHi everyone. Is there a way of access to the names of the components? I know water name is "H2O" instead of "water" because my experience, but what about uncommon components? Would I have to go into HYSYS itself to find out theirs? Thanks.
ReplyDeleteHow would you extract individual phase properties ie. Vapour phase molecular weight, aqueous liquid mass flow etc. Thanks.
ReplyDeleteI have taken this useful tutorial and have written a second one with more information about the objects. How to read streams including its values in differents units. It is on https://www.linkedin.com/pulse/importing-data-from-aspen-hysys-excel-introduction-contreras-navas/
ReplyDeleteThis problem has bothered me for a long time and it is finally solved.
ReplyDeleteThank you very much!
wowwww, thanks a lot dear. I had problem with this one for a long time. now, I know how to access molar composition in hysys. thanksss
ReplyDeleteEskişehir
ReplyDeleteDenizli
Malatya
Diyarbakır
Kocaeli
LJB
yozgat
ReplyDeletetunceli
hakkari
zonguldak
adıyaman
3QU
whatsapp görüntülü show
ReplyDeleteücretli.show
ZC7
51B3C
ReplyDeleteTrabzon Evden Eve Nakliyat
Denizli Şehirler Arası Nakliyat
Denizli Lojistik
Amasya Evden Eve Nakliyat
Van Şehir İçi Nakliyat
Amasya Şehir İçi Nakliyat
Bolu Evden Eve Nakliyat
Samsun Şehirler Arası Nakliyat
Yenimahalle Boya Ustası
815FD
ReplyDeleteKarabük Parça Eşya Taşıma
Amasya Parça Eşya Taşıma
Mardin Parça Eşya Taşıma
Ünye Çekici
Kocaeli Şehirler Arası Nakliyat
Pursaklar Parke Ustası
Keçiören Boya Ustası
Balıkesir Şehirler Arası Nakliyat
Artvin Lojistik
E04E2
ReplyDeletesafepal
defilama
arbitrum
ledger desktop
sushi
trezor suite
zkswap
dexscreener
looksrare
شركة تنظيف سجاد بالجبيل 2Y9ja1WlYK
ReplyDeleteشركة تنظيف مجالس بخميس مشيط O2o0nHcWOy
ReplyDelete