Public Sub PlacePunchFeature()
' Get the active sheet metal document and component
' definition of the active document.
On Error Resume Next
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument
If Err Then
MsgBox "A part must be active."
Exit Sub
End If
Dim oSMDef As SheetMetalComponentDefinition
Set oSMDef = oPartDoc.ComponentDefinition
' Get the selected face that will be used for the creation
' of the sketch that will contain the sketch points.
Dim oFace As Face
Set oFace = oPartDoc.SelectSet.Item(1)
If Err Then
MsgBox "A planar face must be selected."
Exit Sub
End If
On Error GoTo 0
Dim oEdge As Edge
Set oEdge = oFace.Edges.Item(1)
' If oFace.SurfaceType = kPlaneSurface Then
' MsgBox "A planar face must be selected."
' Exit Sub
' End If
' Create a sketch on the selected face.
Dim oSketch As PlanarSketch
Set oSketch = oSMDef.Sketches.Add(oFace)
' Create some points on the sketch. The model will need to
' be of a size that these points lie on the model.
Dim oPoints As ObjectCollection
Set oPoints = ThisApplication.TransientObjects.CreateObjectCollection
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry
Dim oPoint As SketchPoint
Set oPoint = oSketch.SketchPoints.Add(oTG.CreatePoint2d(-2, -2), True)
Call oPoints.Add(oPoint)
Dim oSMFeatures As SheetMetalFeatures
Set oSMFeatures = oSMDef.Features
' Create an iFeatureDefinition object for a punch tool.
Dim oiFeatureDef As iFeatureDefinition
Set oiFeatureDef = oSMFeatures.PunchToolFeatures.CreateiFeatureDefinition( _
"C:\Users\Public\Documents\Autodesk\Inventor 2015\Catalog\Punches\keyhole.ide")
' Set the input.
Dim oInput As iFeatureInput
For Each oInput In oiFeatureDef.iFeatureInputs
Dim oParamInput As iFeatureParameterInput
Select Case oInput.Name
Case "Length"
Set oParamInput = oInput
oParamInput.Expression = "1 in"
Case "Hole_Diameter"
Set oParamInput = oInput
oParamInput.Expression = "0.5 in"
Case "Slot_Width"
Set oParamInput = oInput
oParamInput.Expression = "0.3875 in"
Case "Fillet"
Set oParamInput = oInput
oParamInput.Expression = "0.0625 in"
Case "Thickness"
Set oParamInput = oInput
oParamInput.Expression = "0.125 in"
End Select
Next
Dim oPunchTool As PunchToolFeature
Set oPunchTool = oSMFeatures.PunchToolFeatures.Add(oPoints, oiFeatureDef, 0#)
Dim oObCol As ObjectCollection
Set oObCol = ThisApplication.TransientObjects.CreateObjectCollection
Call oObCol.Add(oPunchTool)
Dim oRectan As RectangularPatternFeature
Set oRectan = oSMFeatures.RectangularPatternFeatures.Add(oObCol, oEdge, True, 2, 3)
End Sub