|
|
|
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
'// Use:
|
|
'// This program demonstrates the
creation of a punch tool feature.
|
|
'// It uses one of the punch features
that’s delivered with Inventor.
|
|
'// It assumes you already have an
existing sheet metal part and have
|
|
'// selected a face to place the punch
feature on. The selected face
|
|
'// should be large so there is room for
the punch features.
|
|
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
Public Sub PlacePunchFeature()
|
|
|
|
' Set a reference to the sheet metal
document.
|
|
' This assumes a part document is
active.
|
|
Dim oPartDoc As PartDocument
|
|
oPartDoc =
_InvApplication.ActiveDocument
|
|
|
|
' Make sure the document is a sheet
metal document.
|
|
If oPartDoc.SubType <>
"{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
|
|
MsgBox("A sheet metal
document must be open.")
|
|
Exit Sub
|
|
End If
|
|
|
|
Dim oSMDef As
SheetMetalComponentDefinition
|
|
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
|
|
|
|
Try
|
|
oFace =
oPartDoc.SelectSet.Item(1)
|
|
Catch
|
|
MsgBox("A planar face must
be selected.")
|
|
Exit Sub
|
|
End Try
|
|
|
|
If oFace.SurfaceType <>
SurfaceTypeEnum.kPlaneSurface Then
|
|
MsgBox("A planar face must
be selected.")
|
|
Exit Sub
|
|
End If
|
|
|
|
' Create a sketch on the selected
face.
|
|
Dim oSketch As PlanarSketch
|
|
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
|
|
oPoints =
_InvApplication.TransientObjects.CreateObjectCollection
|
|
|
|
Dim oTG As TransientGeometry
|
|
oTG =
_InvApplication.TransientGeometry
|
|
|
|
Dim oPoint As SketchPoint
|
|
oPoint =
oSketch.SketchPoints.Add(oTG.CreatePoint2d(8, 8), True)
|
|
Call oPoints.Add(oPoint)
|
|
|
|
oPoint =
oSketch.SketchPoints.Add(oTG.CreatePoint2d(12, 6), True)
|
|
Call oPoints.Add(oPoint)
|
|
|
|
oPoint =
oSketch.SketchPoints.Add(oTG.CreatePoint2d(10, 10), False)
|
|
Call oPoints.Add(oPoint)
|
|
|
|
Dim oSMFeatures As SheetMetalFeatures
|
|
oSMFeatures = oSMDef.Features
|
|
|
|
' Create an iFeatureDefinition object
for a punch tool.
|
|
Dim oiFeatureDef As
iFeatureDefinition
|
|
oiFeatureDef =
oSMFeatures.PunchToolFeatures.CreateiFeatureDefinition(OpenFile("iFeature
Def (*.ide)|*.ide"))
|
|
|
|
' Set the input.
|
|
Dim oInput As iFeatureInput
|
|
For Each oInput In
oiFeatureDef.iFeatureInputs
|
|
Dim oParamInput As
iFeatureParameterInput
|
|
Select Case oInput.Name
|
|
Case "Length"
|
|
oParamInput = oInput
|
|
oParamInput.Expression =
"1 in"
|
|
Case
"Hole_Diameter"
|
|
oParamInput = oInput
|
|
oParamInput.Expression =
"0.5 in"
|
|
Case "Slot_Width"
|
|
oParamInput = oInput
|
|
oParamInput.Expression =
"0.3875 in"
|
|
Case "Fillet"
|
|
oParamInput = oInput
|
|
oParamInput.Expression =
"0.0625 in"
|
|
Case "Thickness"
|
|
oParamInput = oInput
|
|
oParamInput.Expression =
"0.125 in"
|
|
End Select
|
|
Next
|
|
|
|
' Create the iFeature at a 45 degree
angle.
|
|
Dim oPunchTool As PunchToolFeature
|
|
oPunchTool =
oSMFeatures.PunchToolFeatures.Add(oPoints, oiFeatureDef, System.Math.PI / 4)
|
|
|
|
End Sub
|