Inserting an Ifeature into a part from a table using VBA

Inserting an Ifeature into a part from a table using VBA

austen_27_t
Contributor Contributor
1,003 Views
7 Replies
Message 1 of 8

Inserting an Ifeature into a part from a table using VBA

austen_27_t
Contributor
Contributor

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

0 Likes
1,004 Views
7 Replies
Replies (7)
Message 2 of 8

clutsa
Collaborator
Collaborator

I set this to a iFeature of my own and it works fine. Are you sure you're finding a row?

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 NOT 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 '<--this needs to be "Size"
bFoundSize = True
Exit For
End If
Next

If Not bFoundSize Then 
MsgBox "The column ""Size"" was not found." '<--Are you looking for size or member?
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
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 3 of 8

austen_27_t
Contributor
Contributor

I found out the problem earlier today. The iFeatures i was creating had two selectable position geometries, a planar face and a revolve axis. So now i need to find out how to add in code that would allow me to also select a revolve axis for my ifeature.

0 Likes
Message 4 of 8

clutsa
Collaborator
Collaborator

Would something like this work?

RevAxis = ThisApplication.CommandManager.Pick(kAllLinearEntities, "Pick a revolved axis")

you could use it to pick the face too

' Get the selected face to use as input for the iFeature.
Dim oFace As Face
'Set oFace = oPartDoc.SelectSet.Item(1)
Set oFace = ThisApplication.CommandManager.Pick(kAllPlanarEntities, "Pick a planar face")
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 5 of 8

austen_27_t
Contributor
Contributor

What would i Dim RevAxis as?

0 Likes
Message 6 of 8

austen_27_t
Contributor
Contributor

Also i would need to call out the axis as another case so it needs to be defined as an input

0 Likes
Message 7 of 8

clutsa
Collaborator
Collaborator

I agree it would have to be defined as an input. Could you post your .ide file and I can take a look. It's hard to tell you what it needs to be without the file itself (I only got this far because I had a .ide of my own creation but I don't really want to make another just for testing)

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 8 of 8

austen_27_t
Contributor
Contributor

It is not letting me post the ide file. I have attached a screen shot of the position geometry and the ipt file

0 Likes