Collect HoleWizardFeature(s) on a Face

I'm trying to build a list of all HoleWizardFeature(s) on a face in the context of an assembly. This needs to include features that start on the face as well as any thru holes that break through the face. The purpose is to build a selection list for another macro that copies holes from one component to another.

The following function getHolesInFace takes a Face2 and should return an array of Features of type HoleWzd that intersect that face. It fails to get all intersecting holes.

Private Function getHolesInFace(swParentFace As SldWorks.Face2) As Variant

    Dim swFeature   As SldWorks.Feature

    Dim swEdge      As SldWorks.Edge

    Dim swFace      As SldWorks.Face2

    Dim vFaces      As Variant

    Dim vEdge       As Variant

    Dim swHoleWizardFeatures() As SldWorks.Feature

   

    Dim found   As Boolean

    Dim i       As Integer

   

   

    ReDim swHoleWizardFeatures(0)

    Set swHoleWizardFeatures(0) = Nothing

    For Each vEdge In swParentFace.GetEdges

        Set swEdge = vEdge

        vFaces = swEdge.GetTwoAdjacentFaces2

       

        'check the first face from getTwoAdjacentFaces

        Set swFeature = Nothing

        If Not vFaces(0) Is Nothing Then

            Set swFace = vFaces(0)

            Set swFeature = swFace.GetFeature

            Debug.Print swFeature.GetTypeName2

            Debug.Print swFeature.Name

            If Not swFeature.GetTypeName2 = "HoleWzd" Then

                'set Feature to Nothing if it isn't a HoleWizardFeature

                Set swFeature = Nothing

            End If

        End If

       

        'check the second face from getTwoAdjacentFaces

        If swFeature Is Nothing Then

            If Not vFaces(1) Is Nothing Then

                Set swFace = vFaces(0)

                Set swFeature = swFace.GetFeature

                Debug.Print swFeature.GetTypeName2

                Debug.Print swFeature.Name

                If Not swFeature.GetTypeName2 = "HoleWzd" Then

                    'set Feature to Nothing if it isn't a HoleWizardFeature

                    Set swFeature = Nothing

                End If

            End If

        End If

       

        If Not swFeature Is Nothing Then

           'insert the feature into the array if it is unique

            found = False

            For i = 0 To UBound(swHoleWizardFeatures)

                If Not swHoleWizardFeatures(i) Is Nothing Then

                    If swHoleWizardFeatures(i).Name = swFeature.Name Then

                        found = True

                        Exit For

                    End If

                End If

            Next i

            If Not found Then

                If Not swHoleWizardFeatures(0) Is Nothing Then

                    ReDim Preserve swHoleWizardFeatures(UBound(swHoleWizardFeatures) + 1)

                End If

                Set swHoleWizardFeatures(UBound(swHoleWizardFeatures)) = swFeature

            End If

        End If

    Next vEdge

   

    Debug.Print "hole Count:"; (UBound(swHoleWizardFeatures) + 1)

    getHolesInFace = swHoleWizardFeatures

End Function

The Face2 that I pass as an argument is selected in the image below. You can see that the 11.0 dia holes and the 8H7 holes(green) interesect said Face.

Immediate Window:

ICE

Boss-Extrude5

ICE

Boss-Extrude5

ICE

Cut-Extrude1

ICE

Cut-Extrude1

ICE

Cut-Extrude1

ICE

Cut-Extrude1

ICE

Cut-Extrude1

ICE

Cut-Extrude1

HoleWzd

Ø11.0 (11) Diameter Hole1

HoleWzd

Ø11.0 (11) Diameter Hole1

HoleWzd

Ø11.0 (11) Diameter Hole1

HoleWzd

Ø11.0 (11) Diameter Hole1

ICE

Cut-Extrude1

ICE

Cut-Extrude1

ICE

Cut-Extrude1

ICE

Cut-Extrude1

hole Count: 1

It seems to be finding edges associated with the "11.0 Dia" clearance holes but not the 8H7 reamed holes. Both of these are hole wizard features that appear to intersect the face in question.

I believe I've narrowed the problem down to Face2::GetEdges. It is not returning the edges at the intersection of the 8H7 hole features and the face (selected below).

Looking further, it appears that the CutExtrude feature that generated the Face was created after the 8H7 holes. The 11.0 Dia holes were created after the CutExtrude. I can imagine why that would make a difference but don't know how to use that information to proceed. My function needs to return the H7 hole regardless of its order in the feature tree. There should be a way of accessing those edges.

Does anyone have experience with this? Any suggestions are appreciated.

Thanks,

John Alexander

SolidworksApi macros