﻿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.ComplexStrings2d complexStrings2d = null;
            SolidEdgeFrameworkSupport.ComplexString2d complexString2d = null;
            SolidEdgeFrameworkSupport.Lines2d lines2d = 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;
                draftDocument = (SolidEdgeDraft.DraftDocument)documents.Add("SolidEdge.DraftDocument");
                sheet = draftDocument.ActiveSheet;
                lines2d = sheet.Lines2d;
                complexStrings2d = sheet.ComplexStrings2d;

                line2d1 = lines2d.AddBy2Points(0.1, 0.1, 0.2, 0.2);
                line2d2 = lines2d.AddBy2Points(0.2, 0.2, 0.4, 0.2);
                line2d3 = lines2d.AddBy2Points(0.4, 0.2, 0.5, 0.1);

                var members = (System.Array)new object[] { line2d1, line2d2, line2d3 };

                complexString2d = complexStrings2d.AddByObjects(members.Length, ref members);

                complexString2d.RemoveMember(line2d3);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                OleMessageFilter.Unregister();
            }
        }
    }
}