﻿using System;
using System.Runtime.InteropServices;

namespace Examples
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application = null;
            SolidEdgeAssembly.AssemblyDocument assemblyDocument = null;
            SolidEdgeAssembly.Relations3d relations3d = null;
            SolidEdgeAssembly.AngularRelation3d angularRelation3d = 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");
                assemblyDocument = application.ActiveDocument as SolidEdgeAssembly.AssemblyDocument;

                if (assemblyDocument != null)
                {
                    relations3d = assemblyDocument.Relations3d;

                    for (int i = 1; i <= relations3d.Count; i++)
                    {
                        angularRelation3d = relations3d.Item(i) as SolidEdgeAssembly.AngularRelation3d;

                        if (angularRelation3d != null)
                        {
                            attributeSets = (SolidEdgeFramework.AttributeSets)angularRelation3d.AttributeSets;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                OleMessageFilter.Unregister();
            }
        }
    }
}