﻿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.Occurrences occurrences = null;
            SolidEdgeAssembly.Occurrence occurrence = 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)
                {
                    occurrences = assemblyDocument.Occurrences;
                    occurrence = occurrences.Item(1);

                    double OriginX = 0.05;
                    double OriginY = 0.025;
                    double OriginZ = 0.075;
                    double AngleX = Math.PI / 3;
                    double AngleY = Math.PI / 4;
                    double AngleZ = Math.PI / 5;

                    occurrence.PutTransform(OriginX, OriginY, OriginZ, AngleX, AngleY, AngleZ);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                OleMessageFilter.Unregister();
            }
        }
    }
}