﻿using System;
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;
            SolidEdgeGeometry.Body body = null;
            SolidEdgeGeometry.Edges edges = null;
            SolidEdgeGeometry.Edge edge = null;
            SolidEdgeGeometry.Ellipse ellipse = 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);
                    body = (SolidEdgeGeometry.Body)model.Body;

                    var EdgeType = SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryEllipse;

                    edges = (SolidEdgeGeometry.Edges)body.Edges[EdgeType];

                    if (edges.Count > 0)
                    {
                        edge = (SolidEdgeGeometry.Edge)edges.Item(1);
                        ellipse = (SolidEdgeGeometry.Ellipse)edge.Geometry;

                        var ellipseType = ellipse.Type;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                OleMessageFilter.Unregister();
            }
        }
    }
}