﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace Examples
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application = null;
            SolidEdgePart.PartDocument partDocument = null;
            SolidEdgePart.Models models = null;
            SolidEdgePart.Model model = null;
            SolidEdgePart.RevolvedCutouts revolvedCutouts = null;
            SolidEdgePart.RevolvedCutout revolvedCutout = null;

            try
            {
                // See "Handling 'Application is Busy' and 'Call was Rejected By Callee' errors" topic.
                OleMessageFilter.Register();

                // Attempt to connect to a running instance of Solid Edge.
                application = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");
                partDocument = application.ActiveDocument as SolidEdgePart.PartDocument;

                if (partDocument != null)
                {
                    models = partDocument.Models;
                    model = models.Item(1);
                    revolvedCutouts = model.RevolvedCutouts;

                    for (int i = 1; i <= revolvedCutouts.Count; i++)
                    {
                        revolvedCutout = revolvedCutouts.Item(i);

                        var topCap = (SolidEdgeGeometry.Face)revolvedCutout.TopCap;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                OleMessageFilter.Unregister();
            }
        }
    }
}