﻿using System.IO;
using System.Runtime.InteropServices;

internal static class Example
{
    [STAThread()]
    public static void Main()
    {
        SolidEdgeFramework.Application objApplication = null;
        SolidEdgePart.PartDocument objPartDocument = null;
        SolidEdgePart.StudyOwner objStudyOwner = null;
        SolidEdgePart.Study objStudy = null;
        SolidEdgePart.ConnectorOwner objConnectorOwner = null;
        SolidEdgePart.FEAConnector objConnector = null;
        SolidEdgePart.Model objModel = null;
        SolidEdgePart.ExtrudedProtrusion objExtProt = null;
        SolidEdgeGeometry.Faces objFaces = null;
        SolidEdgeGeometry.Face[] objFaceArray = new SolidEdgeGeometry.Face[2];

        try
        {
            OleMessageFilter.Register();

            // Connect to Solid Edge
            objApplication = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");
            objPartDocument = objApplication.ActiveDocument;

            objStudyOwner = objPartDocument.StudyOwner;
            objStudy = objStudyOwner.Item(1);
            objStudy.GetConnectorOwner(objConnectorOwner);
            objConnector = objConnectorOwner.Item(1);

            // Get Model
            objModel = objPartDocument.Models.Item(1);

            // Get Protrusion.
            objExtProt = objModel.ExtrudedProtrusions.Item(1);

            // Get faces collection
            objFaces = objExtProt.Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll);

            // Add faces in array.
            objFaceArray[0] = objFaces.Item(1);
            objFaceArray[1] = objFaces.Item(2);

            //Set these faces as master geometries.
            objConnector.SetSlaveGeometries(objFaceArray);

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        finally
        {
            OleMessageFilter.Revoke();
        }
    }
}