﻿Option Infer On

Imports System
Imports System.Collections.Generic
Imports System.Runtime.InteropServices

Namespace Examples
    Friend Class Program
        <STAThread>
        Shared Sub Main(ByVal args() As String)
            Dim application As SolidEdgeFramework.Application = Nothing
            Dim partDocument As SolidEdgePart.PartDocument = Nothing
            Dim models As SolidEdgePart.Models = Nothing
            Dim model As SolidEdgePart.Model = Nothing
            Dim drafts As SolidEdgePart.Drafts = Nothing
            Dim draft As SolidEdgePart.Draft = Nothing

            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 = DirectCast(Marshal.GetActiveObject("SolidEdge.Application"), SolidEdgeFramework.Application)
                partDocument = TryCast(application.ActiveDocument, SolidEdgePart.PartDocument)

                If partDocument IsNot Nothing Then
                    models = partDocument.Models
                    model = models.Item(1)
                    drafts = model.Drafts

                    For i As Integer = 1 To drafts.Count
                        draft = drafts.Item(i)

                        Dim FaceType = SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll
                        Dim faces = CType(draft.Faces(FaceType), SolidEdgeGeometry.Edges)
                    Next i
                End If
            Catch ex As System.Exception
                Console.WriteLine(ex)
            Finally
                OleMessageFilter.Unregister()
            End Try
        End Sub
    End Class
End Namespace