Inserting an Ifeature into a part from a table using VBA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to make a program where you will be able to select an Ifeature and a part from a drop down meanu and it be placed into a basic part. Currently i just want to get the code to place the Ifeature on the separate part that is open in inventor.
I am using the code from the inventor help site, but it is not working. The error arises at the very last line of code.
Ive adjusted it a little to get my files to work in it.
I would appreciate any help
Thank You
Public Sub TableIfeature()
' Get the part 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 oPartDef As PartComponentDefinition
Set oPartDef = oPartDoc.ComponentDefinition
' Get the selected face to use as input for the iFeature.
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
If oFace.SurfaceType = kPlaneSurface Then
MsgBox "A planar face must be selected."
Exit Sub
End If
Dim oFeatures As PartFeatures
Set oFeatures = oPartDef.Features
' Create an iFeatureDefinition object.
Dim oiFeatureDef As iFeatureDefinition
Set oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition("C:\CAD_Work\MX.ide")
Dim bFoundPlaneInput As Boolean
bFoundPlaneInput = False
Dim oInput As iFeatureInput
For Each oInput In oiFeatureDef.iFeatureInputs
Dim oParamInput As iFeatureParameterInput
Select Case oInput.Name
Case "Profile Plane1"
Dim oPlaneInput As iFeatureSketchPlaneInput
Set oPlaneInput = oInput
oPlaneInput.PlaneInput = oFace
bFoundPlaneInput = True
End Select
Next
If Not bFoundPlaneInput Then
MsgBox "The ide file does not contain an iFeature input named ""Profile Plane1""."
Exit Sub
End If
'** Look through the table to find the row where "Size" is "4.5".
Dim oTable As iFeatureTable
Set oTable = oiFeatureDef.iFeatureTable
' Find the "Size" column.
Dim oColumn As iFeatureTableColumn
Dim bFoundSize As Boolean
bFoundSize = False
For Each oColumn In oTable.iFeatureTableColumns
If oColumn.DisplayHeading = "MEMBER" Then
bFoundSize = True
Exit For
End If
Next
If Not bFoundSize Then
MsgBox "The column ""Size"" was not found."
Exit Sub
End If
' Find the row in the "Size" column with the value of "4.5"
Dim oCell As iFeatureTableCell
bFoundSize = False
For Each oCell In oColumn
If oCell.Value = "5120-MS0F-M8" Then
bFoundSize = True
Exit For
End If
Next
If Not bFoundSize Then
MsgBox "The cell with value ""4.5"" was not found."
Exit Sub
End If
' Set this row as the active row.
oiFeatureDef.ActiveTableRow = oCell.Row
' Create the iFeature.
Dim oiFeature As iFeature
Set oiFeature = oFeatures.iFeatures.Add(oiFeatureDef)
End Sub