AnsweredAssumed Answered

Traverse assembly at component level

Question asked by Damon Frashure on Jan 28, 2015
Latest reply on Jan 29, 2015 by Keith Rice

I'm trying to make this code segment from the Knowledge Base (below) work in SW2010.  When I paste it in the VBA window I get an error because of an invalid number of arguments.  Can someone explain this?  Basically I am trying to write a macro that will let me traverse an assembly and save each part file with a new {sequential} file name and update the assembly at the end.  Thoughts?




Option Explicit

Sub TraverseComponent _

( _

    swComp As SldWorks.Component2, _

    nLevel As Long _


    Dim vChildComp                  As Variant

    Dim swChildComp                 As SldWorks.Component2

    Dim swCompConfig                As SldWorks.Configuration

    Dim sPadStr                     As String

    Dim i                           As Long


    For i = 0 To nLevel - 1

        sPadStr = sPadStr + "  "

    Next i


    vChildComp = swComp.GetChildren

    For i = 0 To UBound(vChildComp)

        Set swChildComp = vChildComp(i)


        TraverseComponent swChildComp, nLevel + 1


        Debug.Print sPadStr & swChildComp.Name2 & " <" & swChildComp.ReferencedConfiguration & ">"

    Next i

End Sub

Sub main()

    Dim swApp                       As SldWorks.SldWorks

    Dim swModel                     As SldWorks.ModelDoc2

    Dim swAssy                      As SldWorks.AssemblyDoc

    Dim swConf                      As SldWorks.configuration

    Dim swRootComp                  As SldWorks.Component2

    Dim bRet                        As Boolean


    Set swApp = CreateObject("SldWorks.Application")

    Set swModel = swApp.ActiveDoc

    Set swConf = swModel.GetActiveConfiguration

    Set swRootComp = swConf.GetRootComponent3(true)


    Debug.Print "File = " & swModel.GetPathName


    TraverseComponent swRootComp, 1

End Sub