AnsweredAssumed Answered

Components in Each BOM Table Row Example error

Question asked by Henrich-Jürgen Kuklane on Sep 4, 2015
Latest reply on Sep 16, 2015 by Ivana Kolin



I have a problem maybe someone can help me.

Problem is in Main sub " Set swDraw = swModel "Type missmatch here"". Maybe its stupid question but i am new to solidworks

I am using solidworks 2015 SP 3.0


Option Explicit


Sub ProcessTableAnn(swApp As SldWorks.SldWorks, swModel As SldWorks.ModelDoc2, swTableAnn As SldWorks.TableAnnotation, ConfigName As String)


    Dim nNumRow As Long

    Dim J As Long

    Dim I As Long

    Dim ItemNumber As String

    Dim PartNumber As String


    Debug.Print "   Table Title        " & swTableAnn.Title


    nNumRow = swTableAnn.RowCount


    Dim swBOMTableAnn As BomTableAnnotation

    Set swBOMTableAnn = swTableAnn


    For J = 0 To nNumRow - 1

        Debug.Print "   Row Number " & J & " Component Count  : " & swBOMTableAnn.GetComponentsCount2(J, ConfigName, ItemNumber, PartNumber)

        Debug.Print "       Item Number  : " & ItemNumber

        Debug.Print "       Part Number  : " & PartNumber


        Dim vPtArr As Variant

        Dim swComp As Object

        Dim pt As Object

        Dim compPath As String


        vPtArr = swBOMTableAnn.GetComponents2(J, ConfigName)


        If (Not IsEmpty(vPtArr)) Then

            For I = 0 To UBound(vPtArr)

                Set pt = vPtArr(I)

                Set swComp = pt

                If Not swComp Is Nothing Then

                    Debug.Print "           Component Name :" & swComp.Name2 & "      Configuration Name : " & swComp.ReferencedConfiguration

                    Debug.Print "           Component Path :" & swComp.GetPathName


                    Debug.Print "  Could not get component."

                End If


        End If

    Next J

End Sub


Sub ProcessBomFeature(swApp As SldWorks.SldWorks, swModel As SldWorks.ModelDoc2, swBomFeat As SldWorks.BomFeature)


    Dim swFeat As SldWorks.Feature

    Dim vTableArr As Variant

    Dim vTable As Variant

    Dim vConfigArray As Variant

    Dim vConfig As Variant

    Dim ConfigName As String

    Dim swTable As SldWorks.TableAnnotation


    Set swFeat = swBomFeat.GetFeature

    vTableArr = swBomFeat.GetTableAnnotations


    For Each vTable In vTableArr

        Set swTable = vTable

        vConfigArray = swBomFeat.GetConfigurations(True, True)

        For Each vConfig In vConfigArray

             ConfigName = vConfig

             Debug.Print "-------------------------------------------------------"

             Debug.Print " Component for Configuration : " & ConfigName

             ProcessTableAnn swApp, swModel, swTable, ConfigName

        Next vConfig

    Next vTable


End Sub


Sub main()


    Dim swApp As SldWorks.SldWorks

    Dim swModel As SldWorks.ModelDoc2

    Dim swDraw As SldWorks.DrawingDoc

    Dim swFeat As SldWorks.Feature

    Dim swBomFeat As SldWorks.BomFeature


    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swDraw = swModel "Type missmatch"

    Set swFeat = swModel.FirstFeature


    Do While Not swFeat Is Nothing

        If "BomFeat" = swFeat.GetTypeName Then

            Debug.Print "******************************"

            Debug.Print "Feature Name : " & swFeat.Name


            Set swBomFeat = swFeat.GetSpecificFeature2


            ProcessBomFeature swApp, swModel, swBomFeat

        End If

        Set swFeat = swFeat.GetNextFeature


End Sub