Example 2 - faces2modelcolor.swb

'****************************************************************************
' macro written on 03/23/99 by Joe Jones of New Hampshire CAD  www.nhcad.com
' this macro will parse all model faces, setting their color
' to "use model color"
'
'****************************************************************************
Dim swApp, modelDoc, partDoc As Object
Dim Body, Face, FeatureObj As Object
Dim faceCnt, I As Integer
 
Sub Main()
    Set swApp = CreateObject("SldWorks.Application")  ' attach to SolidWorks

    ' 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 the program again.", vbCritical)
        swApp.Visible = True
        End
    End If

    ' get Body for current part
    Set Body = modelDoc.Body
    If Body Is Nothing Then
         msgbox("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
        retval = face.select(1)
        ModelDoc.SelectedFaceProperties 0, 0, 0, 0, 0, 0, 0, 1, ""         
        Set Face = Face.GetNextFace
        faceCnt = faceCnt + 1
    Wend
 
    MsgBox(Str(faceCnt) + " faces were converted")
    End
End Sub