AnsweredAssumed Answered

How to get only child component's name while traversing assembly in macro

Question asked by Josh Hixon on Jun 19, 2018
Latest reply on Jun 19, 2018 by Josh Hixon

I am trying to use a macro to compile a custom BOM as a CSV file and am running into a problem with getting the name of the components and sub-assembly components as I traverse the assembly.  How do you get this information at the component file level vs at the assembly feature tree level?

 

When writing the name of the component it can not have the instance in it, or the assembly first with child component after.

What it is: component -1                                        what I want: component

What it is: component-1/Child-1                            what I want: Child

 

so here is the section of code that is traversing the assembly and writing different values based on certain info in RawMaterial.

For i = 0 To UBound(vComps)

        Set swComp = vComps(i)

        Set swCompModel = swComp.GetModelDoc2

        If swCompModel.GetType = swDocPART Then

        If swComp.ExcludeFromBOM = False Then

       

            'Set raw material check ====================================================

           

            check = Left(swCompModel.CustomInfo("Rawmaterial"), 1)

           

            If check = "F" Then

            Debug.Print "Number: " & swComp.Name

           

            Else

                If check = "I" Then

                Debug.Print "Number: " & swComp.Name

               

                Else

                    If check = "D" Then

                    Debug.Print "Number: " & swComp.Name

                   

                    Else

                    Debug.Print "Number: " & swCompModel.CustomInfo("RawMaterial")

            End If

            End If

            End If

            '====================================================

        End If

        End If

    Next i

End Sub

Outcomes