﻿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.Lines2d lines2d = null;
            SolidEdgeFrameworkSupport.Line2d line2d = null;
            SolidEdgeFrameworkSupport.Line2d line2d1 = null;
            SolidEdgeFrameworkSupport.Line2d line2d2 = null;
            SolidEdgeFrameworkSupport.Line2d line2d3 = 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));
                lines2d = profile.Lines2d;

                line2d1 = lines2d.AddBy2Points(0, 0, 0.1, 0);
                line2d2 = lines2d.AddBy2Points(0.1, 0, 0.1, 0.1);
                line2d3 = lines2d.AddAsChamfer(line2d1, line2d2, 0.05, 0.03, 0.04, 0.03);

                for (int i = 1; i <= lines2d.Count; i++)
                {
                    line2d = lines2d.Item(i);

                    object Recurse = false;
                    var key = line2d.Key[Recurse];
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                OleMessageFilter.Unregister();
            }
        }
    }
}