﻿using System;
using System.Runtime.InteropServices;

namespace Examples
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application = null;
            SolidEdgeDraft.DraftDocument draftDocument = null;
            SolidEdgeDraft.Sheet sheet = null;
            SolidEdgeFramework.Layers layers = null;
            SolidEdgeFramework.Layer layer = null;
            SolidEdgeFramework.AttributeSets attributeSets = 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");
                draftDocument = application.ActiveDocument as SolidEdgeDraft.DraftDocument;

                if (draftDocument != null)
                {
                    sheet = draftDocument.ActiveSheet;
                    layers = sheet.Layers;
                    layer = layers.Add("Test");
                    layer.Delete();
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                OleMessageFilter.Unregister();
            }
        }
    }
}