Read Streams Data from a CHEMCAD Flowsheet using MATLAB

Any CHEMCAD flowsheet optimization in MATLAB requires reading data from the flowsheet.

 

The code snippet aims to be the shortest possible snippet to demonstrate how MATLAB accesses a CHEMCAD flowsheet. We recommend to include an exception handling routine, even though the snippet would work without it.

%Read the temperature of three streams from your CHEMCAD
%flowsheet "Flash.cc7" using CCAPI

try
%Path to load the CCAPI DLL interface with CHEMCAD
asmInfo = NET.addAssembly('...\...\CGC.CC-API.dll');

%Put your .NET Interface key here
license_key='.......'

%Starting CHEMCAD Server
chemcad = CCAPI.Server(license_key);

%Path to the CHEMCAD flowsheet
path='...\..\Flash.cc7';

%Load the CHEMCAD flowsheet from the specified path

chemcad.LoadFlowsheet(path);
flowsheet=chemcad.CurrentFlowsheet;

%Reading Streamd Data from CHEMCAD flowsheet
streamsCollection=flowsheet.StreamsInCurUnits;

%First stream in the CHEMCAD flowhseet

streamFirst=streamsCollection.GetStreamAt(0);

%Second stream in CHEMCAD flowhseet

streamSecond=streamsCollection.GetStreamAt(1);

%Third stream in CHEMCAD flowhseet

streamThird=streamsCollection.GetStreamAt(2);

%Reading the streams temperature from CHEMCAD flowsheet
%and displaying on MATLAB command widnow

firstStreamTemp=streamFirst.Temperature
secondStreamTemp=streamSecond.Temperature
thidStreamTemp=streamThird.Temperature

%Relasing the COM Object
%and set the CHEMCAD objects to zero

chemcad.Release;
chemcad=0;
asmInfo=0;
flowsheet=0;

 %Exception handling and release CHEMCAD objects
catch e 
   e.message
      if(isa(e,'NET.NetException'))
        e.ExceptionObject
        chemcad.Release;
        chemcad=0;
        asmInfo=0;
        flowsheet=0;
      end
end

Files:
Download Flash.cc7