﻿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;
            SolidEdgeDraft.DraftDocument draftDocument = null;
            SolidEdgeDraft.Sheet sheet = null;
            SolidEdgeFrameworkSupport.Boundaries2d boundaries2d = null;
            SolidEdgeFrameworkSupport.Boundary2d boundary2d = 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;
                draftDocument = (SolidEdgeDraft.DraftDocument)documents.Add("SolidEdge.DraftDocument");
                sheet = draftDocument.ActiveSheet;
                boundaries2d = (SolidEdgeFrameworkSupport.Boundaries2d)sheet.Boundaries2d;

                var Points = (System.Array)new double[] { 0.1, 0.2, 0.3, 0.35, 0.4, 0.1, 0.25, 0.1 };

                boundary2d = boundaries2d.AddByPoints(Points.Length / 2, ref Points);

                for (int i = 1; i <= boundaries2d.Count; i++)
                {
                    boundary2d = boundaries2d.Item(i);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                OleMessageFilter.Unregister();
            }
        }
    }
}