﻿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.RefPlanes refPlanes = null;
            SolidEdgePart.ProfileSets profileSets = null;
            SolidEdgePart.ProfileSet profileSet = null;
            SolidEdgePart.Profiles profiles = null;
            SolidEdgePart.Profile profile = 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;
                refPlanes = partDocument.RefPlanes;

                if (partDocument != null)
                {
                    profileSets = partDocument.ProfileSets;

                    for (int i = 1; i <= profileSets.Count; i++)
                    {
                        profileSet = profileSets.Item(i);
                        profiles = profileSet.Profiles;

                        for (int j = 1; j <= profiles.Count; j++)
                        {
                            profile = profiles.Item(j);

                            var size = profile.Size;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                OleMessageFilter.Unregister();
            }
        }
    }
}