Establish connection between R and Aspen Plus

I am trying to establish a connection between R and Aspen Plus (a chemical process simulator). I have succeeded in making the connection between MATLAB and Aspen Plus (https://www.mathworks.com/matlabcentral/fileexchange/69464-aspen-plus-matlab-link), but not with R.

I believe the problem is related to creating and invoking a COM server. I would like to be able to perform the same simulation as at https://www.mathworks.com/matlabcentral/fileexchange/69464-aspen-plus-matlab-link, only using R instead of MATLAB.

I have asked this same question to the Aspen Tech Suport Center. Here is there answer: The Aspen Plus Windows user interface is an ActiveX Automation Server. The ActiveX technology (also called OLE Automation) enables an external Windows application to interact with Aspen Plus through a programming interface using a language such as Microsoft's Visual Basic. The server exposes objects through the COM object model. If the R programming language can interact with the COM interface, then it should work. Any ideas?

I have no clue what the status of this project is, but:
https://cran.r-project.org/contrib/extra/dcom/00ReadMe.html

Thank you Mara. I'm using the RDCOMClient package, but still without much success. In matlab I would use the actxserver() function (to create a COM server) and the invoke() function (to invoke a method in the COM object). I'm just not being able to do the same in R;

Assuming you are on Windows, one option would be to try and use VBScript (see this). So all your COM automation codes are in the script, which you simply execute using R.

I have successfully used this technique to open an Excel file, write to a cell which itself triggers a proprietary API available only as an Excel add-in, get the results in Excel, write those to a file and finally read this file in R.

Got it!!!

# Package
library(RDCOMClient)

# COM Object
Aspen <- RDCOMClient::COMCreate("Apwn.Document")

# Path to .bkp simulation file
Path <- "C:/Path to simulation file.bkp"

# Invoke COM Object
RDCOMClient::.COM(obj = Aspen, name = "InitFromFile2", Path)

Aspen[["Visible"]] <- TRUE
Aspen$visible()
Aspen[["SuppressDialogs"]] <- 1
Aspen$SuppressDialogs()

# Reinitialize Simulation
Aspen$Reinit()

# Run Simulation
Aspen$Run2()

# Calling variable result from simulation  
Aspen$Application()$Tree()$FindNode('Variable Explorer Call')$Value()

# Close Aspen Plus
Aspen$Close()
1 Like

If your question's been answered (even if by you), would you mind choosing a solution? (See FAQ below for how).

Having questions checked as resolved makes it a bit easier to navigate the site visually and see which threads still need help.

Thanks

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.