Imports System.IO
Imports System.Runtime.InteropServices
Module Example
    <STAThread()> _
    Sub Main()
        Dim objApplication As SolidEdgeFramework.Application = Nothing
        Dim objPartDocument As SolidEdgePart.PartDocument = Nothing
        Dim objStudyOwner As SolidEdgePart.StudyOwner = Nothing
        Dim objStudy As SolidEdgePart.Study = Nothing
        Dim objMeshOwner As SolidEdgePart.MeshOwner = Nothing
        Dim objMeshControl As SolidEdgePart.MeshControl = Nothing
        Dim objModel As SolidEdgePart.Model = Nothing
        Dim objExtProt As SolidEdgePart.ExtrudedProtrusion = Nothing
        Dim objEdges As SolidEdgeGeometry.Edges = Nothing
        Dim objProxiesArray(1) As Object
        Dim nMeshCtrlType As Integer = 2
        Dim nMCtrlSizeType As Integer = 2 ' Type of size control - Default, Subjective, Custom
        Dim dMCtrlSize As Double = 3.0 ' -1 if Default, 1 to 10 if subjective
        Dim dMCtrlSizeCustom As Double = 0.0028366052049647972 '
        Dim dMCtrlTetGRatio As Double = 1.1 ' Tetrahedral mesh growth ratio - Exposed via VT
        Dim bMidSideNodes As Boolean = True ' Allow mid-side nodes or not
        Dim nSurfElemType As Integer = 1 ' Type of mesh elements in case of surface - quad/tri
        Dim dMCtrlElemSize As Double = 0.0125 ' Element mesh sizing for face & edge - Exposed via VT
        Dim bUseNumElements As Boolean = True ' User number of elements or use element size
        Dim nNumElements As Integer = 1 ' Number of elements - if this value is less than 1 then
        Dim bUseElemsOnLines As Boolean = False
        Dim nNumElemsOnLines As Integer = 1 ' Number of elements on Lines - Exposed via VT
        Dim bUseElemsOnClosedE As Boolean = False
        Dim nNumElemsOnClosedE As Integer = 12 ' Number of elements on closed edges - Exposed via VT
        Dim bUseElemsOnOtherE As Boolean = False
        Dim nNumElemsOnOtherE As Integer = 1 ' Number of elements on other edges - Exposed via VT
        Try
            OleMessageFilter.Register()
            ' Connect to Solid Edge
            objApplication = Marshal.GetActiveObject("SolidEdge.Application")
            objPartDocument = objApplication.ActiveDocument
            objStudyOwner = objPartDocument.StudyOwner
            objStudy = objStudyOwner.Item(1)
            objStudy.GetMeshOwner(objMeshOwner)
            ' Get Model
            objModel = objPartDocument.Models.Item(1)
            ' Get Protrusion.
            objExtProt = objModel.ExtrudedProtrusions.Item(1)
            ' Get Edges Colection
            objEdges = objExtProt.Edges(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll)
            ' Store edge proxies in vector
            objProxiesArray(0) = objEdges.Item(3)
            objProxiesArray(1) = objEdges.Item(4)
            ' Create Mesh Control
            objMeshOwner.AddMeshControl(objProxiesArray, _
                                        nMeshCtrlType, _
                                        nMCtrlSizeType, _
                                        dMCtrlSize, _
                                        dMCtrlSizeCustom, _
                                        dMCtrlTetGRatio, _
                                        bMidSideNodes, _
                                        nSurfElemType, _
                                        dMCtrlElemSize, _
                                        bUseNumElements, _
                                        nNumElements, _
                                        bUseElemsOnLines, _
                                        nNumElemsOnLines, _
                                        bUseElemsOnClosedE, _
                                        nNumElemsOnClosedE, _
                                        bUseElemsOnOtherE, _
                                        nNumElemsOnOtherE, _
                                        objMeshControl)
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        Finally
            OleMessageFilter.Revoke()
        End Try
    End Sub
End Module