Error face not planar on selected part VBA Ifeature

Error face not planar on selected part VBA Ifeature

austen_27_t
Contributor Contributor
1,108 Views
4 Replies
Message 1 of 5

Error face not planar on selected part VBA Ifeature

austen_27_t
Contributor
Contributor

I am trying to insert an i feature just into a basic cube using the code from the inventor help desk but no matter what face i choose i get the planar face needs to be selected error.

I have tried selecting all faces of the cube but none seem to work can anyone tell me why and how to fix?

 

 

Public Sub PlaceTableDriveniFeature()

' 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 'When this is added error message occurs

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")

' Set the input, which in this case is only the sketch plane
' since the other input comes from the table. The parameter input
' should not be available at this point since it can't be changed
' and is controlled by the table.
'
' When an existing table driven iFeature is accessed then this should
' include the parameters so the programmer has access to the corresponding
' reference parameter that's created.
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 "MEMBER" is "M8".
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 MEMBER was not found."
Exit Sub
End If

' Find the row in the "MEMBER column with the value of "M8"
Dim oCell As iFeatureTableCell
bFoundSize = False
For Each oCell In oColumn
If oCell.Value = "M8" Then
bFoundSize = True
Exit For
End If
Next

If Not bFoundSize Then
MsgBox "The cell with value M8 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
Accepted solutions (1)
1,109 Views
4 Replies
Replies (4)
Message 2 of 5

clutsa
Collaborator
Collaborator
Accepted solution

I didn't check this whole thing but I did see this...

Public Sub PlaceTableDriveniFeature()

' 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 'When this is added error message occurs <----- ADDED 'NOT'

    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")

' Set the input, which in this case is only the sketch plane
' since the other input comes from the table. The parameter input
' should not be available at this point since it can't be changed
' and is controlled by the table.
'
' When an existing table driven iFeature is accessed then this should
' include the parameters so the programmer has access to the corresponding
' reference parameter that's created.
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 "MEMBER" is "M8".
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 MEMBER was not found."
    Exit Sub
End If

' Find the row in the "MEMBER column with the value of "M8"
Dim oCell As iFeatureTableCell
bFoundSize = False
For Each oCell In oColumn
    If oCell.Value = "M8" Then
        bFoundSize = True
        Exit For
    End If
Next

If Not bFoundSize Then
    MsgBox "The cell with value M8 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

Message 3 of 5

austen_27_t
Contributor
Contributor

This was one of the errors in the inventor help desk 

I still have another error in that code that i just posted but thank you!

0 Likes
Message 4 of 5

clutsa
Collaborator
Collaborator

Looks like your loops are broken up to much...

Public Sub PlaceTableDriveniFeature()

' 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:\Vault\Workspace\Parts\iFeatures\SAE ORB Port.ide")

' Set the input, which in this case is only the sketch plane
' since the other input comes from the table. The parameter input
' should not be available at this point since it can't be changed
' and is controlled by the table.
'
' When an existing table driven iFeature is accessed then this should
' include the parameters so the programmer has access to the corresponding
' reference parameter that's created.
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 column where header is "MEMBER".
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
        ' Find the row in the "MEMBER column with the value of "M8"
        For Each oCell In oColumn
            If oCell.Value = "M8" Then
                ' Set this row as the active row.
                oiFeatureDef.ActiveTableRow = oCell.Row
                Exit For
            End If
        Next
        Exit For
    End If
Next


If Not bFoundSize Then
    MsgBox "The column MEMBER was not found."
    Exit Sub
End If

' 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 5 of 5

austen_27_t
Contributor
Contributor

Ill give this a try but my error comes in the last line. Ill see if this might fix it 

Thank You

0 Likes