Imports System.Runtime.InteropServices
Public Class CutOut
Private Sub btnCutOut_Click(sender As System.Object, e As System.EventArgs)
Dim objApplication As SolidEdgeFramework.Application = Nothing
Dim objPartDoc As SolidEdgePart.PartDocument = Nothing
Dim objDrawnCut As SolidEdgePart.DrawnCutout = Nothing
Dim objDrawnCuts As SolidEdgePart.DrawnCutouts = Nothing
Dim objModels As SolidEdgePart.Models = Nothing
Dim objModel As SolidEdgePart.Model = Nothing
Dim objProfile As Object
Dim objProfArr(0 To 1) As Object
Dim objLines As Object
Dim lngStatus As Long
Dim objRelns As Object
Dim nCnt As Object
Dim objType As Type = Nothing
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 reference to the open document
objPartDoc = objApplication.ActiveDocument
' Get the models collection
objModels = objPartDoc.Models()
objModel = objModels.Item(1)
objDrawnCuts = objModel.DrawnCutouts
If objDrawnCuts Is Nothing Then
MessageBox.Show("Failed to get collection")
End If
objProfile = objPartDoc.ProfileSets.Add.Profiles.Add(objPartDoc.RefPlanes.Item(3))
objLines = objProfile.Lines2d
Call objLines.AddBy2Points(X1:=-0.08, Y1:=-0.05, X2:=0.06, Y2:=-0.05)
Call objLines.AddBy2Points(X1:=0.06, Y1:=-0.05, X2:=0.06, Y2:=0.04)
Call objLines.AddBy2Points(X1:=0.06, Y1:=0.04, X2:=-0.08, Y2:=0.04)
Call objLines.AddBy2Points(X1:=-0.08, Y1:=0.04, X2:=-0.08, Y2:=-0.05)
Call objLines.AddBy2Points(X1:=-0.5, Y1:=-0.07, X2:=-0.3, Y2:=-0.07)
Call objLines.AddBy2Points(X1:=-0.5, Y1:=-0.07, X2:=-0.5, Y2:=0.07)
Call objLines.AddBy2Points(X1:=-0.5, Y1:=0.07, X2:=-0.3, Y2:=0.07)
Call objLines.AddBy2Points(X1:=-0.3, Y1:=0.07, X2:=-0.3, Y2:=-0.07)
objRelns = objProfile.Relations2d
Call objRelns.AddKeypoint(Object1:=objLines.Item(1), Index1:=SolidEdgeConstants.KeypointIndexConstants.igLineEnd, Object2:=objLines.Item(2), Index2:=SolidEdgeConstants.KeypointIndexConstants.igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines.Item(2), Index1:=SolidEdgeConstants.KeypointIndexConstants.igLineEnd, Object2:=objLines.Item(3), Index2:=SolidEdgeConstants.KeypointIndexConstants.igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines.Item(3), Index1:=SolidEdgeConstants.KeypointIndexConstants.igLineEnd, Object2:=objLines.Item(4), Index2:=SolidEdgeConstants.KeypointIndexConstants.igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines.Item(4), Index1:=SolidEdgeConstants.KeypointIndexConstants.igLineEnd, Object2:=objLines.Item(1), Index2:=SolidEdgeConstants.KeypointIndexConstants.igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines.Item(5), Index1:=SolidEdgeConstants.KeypointIndexConstants.igLineEnd, Object2:=objLines.Item(6), Index2:=SolidEdgeConstants.KeypointIndexConstants.igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines.Item(6), Index1:=SolidEdgeConstants.KeypointIndexConstants.igLineEnd, Object2:=objLines.Item(7), Index2:=SolidEdgeConstants.KeypointIndexConstants.igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines.Item(7), Index1:=SolidEdgeConstants.KeypointIndexConstants.igLineEnd, Object2:=objLines.Item(8), Index2:=SolidEdgeConstants.KeypointIndexConstants.igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines.Item(8), Index1:=SolidEdgeConstants.KeypointIndexConstants.igLineEnd, Object2:=objLines.Item(5), Index2:=SolidEdgeConstants.KeypointIndexConstants.igLineStart)
lngStatus = objProfile.End(ValidationCriteria:=SolidEdgeConstants.ProfileValidationType.igProfileNoSelfIntersect)
If lngStatus <> 0 Then
MessageBox.Show("Profile not closed")
End If
nCnt = objPartDoc.ProfileSets.Count()
'get profiles from profile set
objProfArr(0) = objPartDoc.ProfileSets.Item(2).Profiles.Item(1)
' Create Dimple object
objDrawnCut = objDrawnCuts.AddEx(
1,
objProfArr,
0.05,
SolidEdgePart.DrawnCutoutFeatureConstants.seDrawnCutoutProfileLeft,
SolidEdgePart.DrawnCutoutFeatureConstants.seDrawnCutoutDepthRight,
SolidEdgePart.DrawnCutoutFeatureConstants.seDrawnCutoutMaterialOutside,
0.002,
0.0,
0.001,
SolidEdgePart.DrawnCutoutFeatureConstants.seDrawnCutoutRoundEdges,
SolidEdgePart.DrawnCutoutFeatureConstants.seDrawnCutoutRoundCorners)
If objDrawnCut Is Nothing Then
MessageBox.Show("Failed to Add object")
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class