List UnitOps and Streams

posted in: C#, Code Snippets 0

This code-snippet in C# shows how to list UnitOps and Streams of a CHEMCAD flowsheet. You want to use this method in MATLAB?See here.

using CCAPI;
using System;
using System.IO;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // Initiate a new instance of CHEMCAD
            Console.WriteLine("Initializing CC-API...");
            Server chemcad;
            //Put your .NET Interface key here
            var license_key="...";
            try
            {
                chemcad = new Server(license_key);
            }
            // If the server doesn't respond or 
            // if reply results in end of program:
            catch (Exception ex)
            {
                // Display server message and close after key is pushed
                Console.WriteLine(ex.Message);
                Console.ReadLine();
                return;
            }
 
            // Open a CHEMCAD file relative from the current directory
            string path = Path.Combine(Directory.GetCurrentDirectory(),
            "..\\..\\..\\Deisobutanizer.cc7");
            Console.WriteLine("Opening: " + path + "...\n");
            try
            {
                chemcad.LoadFlowsheet(path);
            }
            // If flowsheet cannot be opened:
            catch (Exception ex)
            {
                // Display error message and close after key is pushed
                Console.WriteLine(ex.Message);
                Console.ReadLine();
                return;
            }
            // Load the flowsheet
            Flowsheet flowsheet = chemcad.CurrentFlowsheet;
 
            // Write into the console
            Console.WriteLine("List of unit operation ids:");
            foreach (var unitOp in flowsheet.UnitOperations)
            {
                Console.Write(unitOp.Id + " ");
            }
            Console.WriteLine();
            Console.WriteLine("List of stream ids:");
            foreach (var stream in flowsheet.StreamsInCurUnits)
            {
                Console.Write(stream.Id + " ");
            }
            Console.ReadLine();
        }
    }
}
 

Output:

Files:
Download Deisobutanizer.cc7