Example 3 - cavityfaces.swb

'**********************************************************
' Cavityfaces.swb	 7/31/00
' This will select all faces that belong to a cavity feature.
'
'**********************************************************
 
SUB Main()
    Dim swApp, modelDoc, partDoc As Object
    Dim Body, Face, FeatureObj As Object
    Dim faceCnt, faceCav, I As Integer

    ' attach to SolidWorks
    Set swApp = CreateObject("SldWorks.Application")

    ' get modelDoc for current part
    Set modelDoc = swApp.ActiveDoc  
    If modelDoc Is Nothing Then
        I = MsgBox("Error - No model loaded!" + Chr(13) + Chr(13) + _ 
          "Open a part or assembly and run program again", vbCritical)
        swApp.Visible = True
        End
    End If

    ' get Body for current part
    Set Body = modelDoc.Body
    If Body Is Nothing Then
        swApp.SendMsgToUser "This program only works on Parts"         
        End
    End If
 
    swApp.Visible = True           ' make SW visible
    modelDoc.ClearSelection        ' clear selection list
 
    Set Face = Body.GetFirstFace   ' Get first face
    faceCnt = 0
    faceCav = 0
    While Not Face Is Nothing
        Set FeatureObj = Face.GetFeature()
        If FeatureObj.gettypename = "Cavity" Then
            Face.Select TRUE  ' add this face to selection
            faceCav = faceCav + 1
        End If
        Set Face = Face.GetNextFace
        faceCnt = faceCnt + 1
    Wend
 
    swApp.SendMsgToUser Str(faceCav) & " faces of " & _
                        Str(faceCnt) & " belong to a cavity"
End Sub