Hello everyone, I am new to this forum!
So my name is Chris and I am currently developing a Reinforcement Learning Model in Python that uses Aspen Plus as the simulator and VBA as a means of connection between the two.
Learning Python, VBA and Aspen has been fun, however I have faced the following issue, whilst trying to make a PFR block through VBA.
As part of the needed input variables for creating the PFR, we need to select the reaction taking place inside the vessel, in my case its named "REAC" as it can be seen in the Figure1 presented below.
As you can see from the VBA code below, I tried inputting "REAC" as a Value to the "RXN_ID" module found through the Variable Explorer:
Sub Add_PFR3(Bcounter, R_Type, Op_Cond, T_PFR, L_PFR, D_PFR, Phase_PFR, Reac_PFR)
Pcounter = "P" & CStr(Bcounter) 'Internal Function to Count the Reaction Modules'
Dim AspenObject As IHapp
Dim Pfr As IHNode
'Chose ASPEN bkp File'
Set AspenObject = GetObject(ThisWorkbook.Path & "\" & Sheet1.Cells(1, 1)) 'Get the name of the bkp file'
Set Pfr = AspenObject.Tree.Elements("Data").Elements("Blocks")
Pfr.Elements.Add (Pcounter & "!RPlug") 'Add PFR in the Flowsheet'
Pfr.Elements(Pcounter).Input.Elements("TYPE").Value = R_Type
Pfr.Elements(Pcounter).Input.OPT_TSPEC.Value = Op_Cond
Pfr.Elements(Pcounter).Input.REAC_TEMP.Value = T_PFR
Pfr.Elements(Pcounter).Input.Elements("LENGTH").Value = L_PFR
Pfr.Elements(Pcounter).Input.Elements("DIAM").Value = D_PFR
Pfr.Elements(Pcounter).Input.Elements("PHASE").Value = Phase_PFR
Pfr.Elements(Pcounter).Input.RXN_ID.Value = Reac_PFR
End Sub
All the variable and code work, except for being able to add Reac_PFR = "REAC" as the Value of the RXN_ID.
I found by choosing the "REAC" reaction manually through the GUI, creates a subfolder in the RXN_ID As it can be seen from the Before and After pictures of the variable explorer in the Attached Figure2.
Hence I thought a solution was to create the node my self as a means of being able to choose the reaction, changing:
Pfr.Elements(Pcounter).Input.RXN_ID.Elements.Add("#0!REAC")
Pfr.Elements(Pcounter).Input.RXN_ID.Elements("#0").Value = Reac_PFR
However this doesn't seem to work.
I have gone through most of the Aspen documentation concerning the creation of block through VBA, but there seems to be no documentation on how to make this exact choice.
Your help would be much appreciated
Chris
Edited by A.D.Christos, 07 May 2021 - 03:11 PM.