﻿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.FeatureControlFrames featureControlFrames = null;
            SolidEdgeFrameworkSupport.FeatureControlFrame featureControlFrame = 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;
                featureControlFrames = (SolidEdgeFrameworkSupport.FeatureControlFrames)sheet.FeatureControlFrames;

                featureControlFrame = featureControlFrames.Add(0.1, 0.1, 0);
                featureControlFrame.PrimaryFrame = "%FL%VB0.001%MC%VBA";
                featureControlFrame.AddVertex(0.2, 0.2, 0);
                featureControlFrame.AddVertex(0.25, 0.225, 0);
                featureControlFrame.BreakLine = true;

                var VerticesList = new List<double>();

                VerticesList.AddRange(new double[] { 0.1, 0.1 });    // First vertex co-ords.
                VerticesList.AddRange(new double[] { 0.15, 0.125 }); // Second vertex co-ords.
                VerticesList.AddRange(new double[] { 0.2, 0.175 });  // Third vertex co-ords.

                var Vertices = (System.Array)VerticesList.ToArray();

                var vertexCount = featureControlFrame.VertexCount;
                featureControlFrame.SetVertices(vertexCount, ref Vertices);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                OleMessageFilter.Unregister();
            }
        }
    }
}