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

namespace Examples
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application = null;
            SolidEdgeFramework.Documents documents = 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;
            SolidEdgeFrameworkSupport.Arcs2d arcs2d = null;
            SolidEdgeFrameworkSupport.Arc2d arc2d = 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");
                documents = application.Documents;
                partDocument = (SolidEdgePart.PartDocument)documents.Add("SolidEdge.PartDocument");
                refPlanes = partDocument.RefPlanes;
                profileSets = partDocument.ProfileSets;
                profileSet = profileSets.Add();
                profiles = profileSet.Profiles;
                profile = profiles.Add(refPlanes.Item(1));
                arcs2d = profile.Arcs2d;

                arc2d = arcs2d.AddByCenterStartEnd(0, 0, 0.05, 0, 0, 0.05);

                double xMinimum;
                double yMinimum;
                double xMaximum;
                double yMaximum;

                arc2d.Range(out xMinimum, out yMinimum, out xMaximum, out yMaximum);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                OleMessageFilter.Unregister();
            }
        }
    }
}