Imports System.Runtime.InteropServices
Public Class EmbossFeature
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim objApplication As SolidEdgeFramework.Application = Nothing
        Dim objDoc As SolidEdgePart.SheetMetalDocument = Nothing
        Dim objEdges As SolidEdgeGeometry.Edges = Nothing
        Dim objTargetBody As Object
        Dim objToolBodies(0 To 0) As Object
        Dim objEmbossFeatures As SolidEdgePart.EmbossFeatures = Nothing
        Dim objEmbossFeature As SolidEdgePart.EmbossFeature = Nothing
        Dim objModel As Object
        Dim objType As Type = Nothing
        Dim numToolsFromFeature As Integer
        Dim objFeatureSetToolBodies(0 To 1) As Object
        Dim objFeatureToolBodies(0 To 0) As Object
        Dim objFeatureGetToolBodies(0 To 1) As Object
        Dim objFeatureSetTargetBody As Object
        Try
            ' Create/get the application with specific settings
            objApplication = Marshal.GetActiveObject("SolidEdge.Application")
            If objApplication Is Nothing Then
                ' Get the type from the Solid Edge ProgID
                objType = Type.GetTypeFromProgID("SolidEdge.Application")
                ' Start Solid Edge
                objApplication = Activator.CreateInstance(objType)
                ' Make Solid Edge visible
                objApplication.Visible = True
            End If
            ' Get the active document.
            objDoc = objApplication.ActiveDocument()
            
            'Creation API:-
            objModel = objDoc.Models.Item(1)
            objTargetBody = objModel.Body()
            objToolBodies(0) = objDoc.Models.Item(2).Body()
            objEmbossFeatures = objModel.EmbossFeatures
            If objEmbossFeatures Is Nothing Then
                MsgBox("Failed to get the EmbossFeatures collection")
            End If
            objEmbossFeature = objEmbossFeatures.Add(objTargetBody,
                               1,
                               objToolBodies,
                               True,
                               True,
                               0.001,
                               0.005,
                               SolidEdgePart.FeaturePropertyConstants.igAddRound,
                               SolidEdgePart.FeaturePropertyConstants.igCornerRound,
                               0.002,
                               0.003)
            If objEmbossFeature Is Nothing Then
                MsgBox("Failed to Add Emboss Feature")
            End If
            ' Check the status of ordered Bead Feature
            If objDoc.ModelingMode = SolidEdgePart.ModelingModeConstants.seModelingModeOrdered Then
                If objEmbossFeature.Status <> SolidEdgePart.FeatureStatusConstants.igFeatureOK Then
                    MsgBox("Error in the Creation of Emboss Feature object")
                End If
            End If
            'Getting and Setting of Feature Parameters:-
            ' Getting the Emboss Feature Values
            ' ********** 1. Thicken **********
            
            If objEmbossFeature.Thicken = False Then
                MsgBox("Error in the Creation of Emboss Feature object - Thicken Parent wrong")
            End If
            ' ********** 2. Side **********
            If objEmbossFeature.Side() <> True Then
                MsgBox("Error in the Creation of Emboss Feature object - Side Parent wrong")
            End If
            ' ********** 3. Clearance **********
            If Math.Abs(objEmbossFeature.Clearance() - 0.001) > 0.00001 Then
                MsgBox("Error in the Creation of Emboss Feature object - ClearanceValue wrong")
            End If
            ' ********** 4. Die Round Option **********
            If objEmbossFeature.DieRounding() <> SolidEdgePart.FeaturePropertyConstants.igAddRound Then
                MsgBox("Error in the Creation of Emboss Feature object - Die Round Option wrong")
            End If
            ' ********** 5. Punch Round Option **********
            If objEmbossFeature.PunchSideRounding() <> SolidEdgePart.FeaturePropertyConstants.igCornerRound Then
                MsgBox("Error in the Creation of Emboss Feature object - Punch Round Option wrong")
            End If
            ' ********** 6. Die Radius **********
            If Math.Abs(objEmbossFeature.DieRadius() - 0.002) > 0.00001 Then
                MsgBox("Error in the Creation of Emboss Feature object - Die Round Radius Value wrong")
            End If
            ' ********** 7. Punch Side Radius **********
            If Math.Abs(objEmbossFeature.PunchSideRadius() - 0.003) > 0.00001 Then
                MsgBox("Error in the Creation of Emboss Feature object - Punch Round Radius Value wrong")
            End If
            ' ********** 8. Tools **********
            Call objEmbossFeature.GetEmbossToolBodies(numToolsFromFeature, objFeatureToolBodies)
            If numToolsFromFeature <> 1 Then
                MsgBox("Error in the Creation of Emboss Feature object - Tools Parent wrong")
            End If
            If objFeatureToolBodies(0) Is Nothing Then
                MsgBox("Error in the Creation of Emboss Feature object - Tool Parent wrong")
            End If
            ' ********** 9. Target **********
            If objEmbossFeature.EmbossTarget() Is Nothing Then
                MsgBox("Error in the Creation of Emboss Feature object - Target Parent wrong")
            End If
            ' Setting the Emboss Feature Values
            ' ********** 1. Punch Side Radius Value Set **********
            objEmbossFeature.PunchSideRadius = 0.002
            If Math.Abs(objEmbossFeature.PunchSideRadius() - 0.002) > 0.00001 Then
                MsgBox("Error in the Creation of Emboss Feature object - Punch Round Radius Value not set")
            End If
            ' ********** 2. Die  Radius Value Set **********
            objEmbossFeature.DieRadius = 0.001
            If Math.Abs(objEmbossFeature.DieRadius() - 0.001) > 0.00001 Then
                MsgBox("Error in the Creation of Emboss Feature object - Die Round Radius Value not set")
            End If
            ' ********** 3. Punch Side Round Option **********
            objEmbossFeature.PunchSideRounding = SolidEdgePart.FeaturePropertyConstants.igNoRound
            If objEmbossFeature.PunchSideRounding() <> SolidEdgePart.FeaturePropertyConstants.igNoRound Then
                MsgBox("Error in the Creation of Emboss Feature object - Punch Side Round Value not set")
            End If
            ' ********** 4. Die Side Round Option **********
            objEmbossFeature.DieRounding = SolidEdgePart.FeaturePropertyConstants.igNoRound
            If objEmbossFeature.DieRounding() <> SolidEdgePart.FeaturePropertyConstants.igNoRound Then
                MsgBox("Error in the Creation of Emboss Feature object - Die Round Value not set")
            End If
            ' ********** 5. Side   **********
            objEmbossFeature.Side = False
            If objEmbossFeature.Side() <> False Then
                MsgBox("Error in the Creation of Emboss Feature object - Side Value not set")
            End If
            ' ********** 6. Clearance   **********
            objEmbossFeature.Clearance = 0.0
            If Math.Abs(objEmbossFeature.Clearance() - 0.0) > 0.00001 Then
                MsgBox("Error in the Creation of Emboss Feature object - Clearance Value not set")
            End If
            ' ********** 7. Tools **********
            numToolsFromFeature = 2
            objFeatureSetToolBodies(0) = objDoc.Models.Item(2).Body()
            objFeatureSetToolBodies(1) = objDoc.Models.Item(3).Body()
            objEmbossFeature.SetEmbossToolBodies(numToolsFromFeature, objFeatureSetToolBodies)
            numToolsFromFeature = 0
            objEmbossFeature.GetEmbossToolBodies(numToolsFromFeature, objFeatureGetToolBodies)
            If numToolsFromFeature <> 2 Then
                MsgBox("Error in the Creation of Emboss Feature object - Tools Parent wrong")
            End If
            For value As Integer = 0 To (numToolsFromFeature - 1)
                If objFeatureGetToolBodies(value) Is Nothing Then
                    MsgBox("Error in the Creation of Emboss Feature object - Tool Parent wrong")
                End If
            Next
            ' ********** 8. Target **********
            objFeatureSetTargetBody = objDoc.Models.Item(4).Body()
            objEmbossFeature.EmbossTarget = objFeatureSetTargetBody
            If objEmbossFeature.EmbossTarget() Is Nothing Then
                MsgBox("Error in the Creation of Emboss Feature object - Target Parent wrong")
            End If
            ' ********** 9. Thicken   **********
            objEmbossFeature.Thicken = False
            If objEmbossFeature.Thicken() <> False Then
                MsgBox("Error in the Creation of Emboss Feature object - Thicken Value not set")
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
            Clipboard.SetText(ex.ToString)
        End Try
    End Sub
End Class