AnsweredAssumed Answered

Prevent a VBA macro from traversing an assembly

Question asked by Darren Smith on Jun 19, 2019
Latest reply on Jun 24, 2019 by Luke Malpass

Can anybody help?

I have the following VBA macro function to traverse through an assembly.....


Public Function TraverseComponent(swComp As SldWorks.Component2, nLevel As Long)
    Dim vChildComp As Variant

    Dim swChildComp As SldWorks.Component2

    Dim swConfig As SldWorks.Configuration

    vChildComp = swComp.GetChildren

    For Counter = 0 To UBound(vChildComp)
        Set swChildComp = vChildComp(Counter)

        TraverseComponent swChildComp, nLevel + 1

        Set Part = swChildComp.GetModelDoc()

        FileName = swChildComp.GetPathName

        Msgbox (FileName)

        vChildComp2 = swChildComp.GetChildren
    Next Counter
End Function


I need to prevent the macro from traversing the assembly if the SolidWorks document has been inserted into an assembly from the "Design Library".


For example,

Say I have created an assembly using my own SolidWorks parts. Now, if I insert an assembly of (for example) a valve downloaded from a supplier, this document can also be an assembly containing several parts. I need the vba macro to only display (for testing only) the assembly part number in the msgbox and not all of the parts that make up the assembly.


Is this possible!


Many thanks in advance!!!