14 Replies Latest reply on Oct 5, 2018 10:38 AM by Cad Admin

    API - VBA Check ChildComponentDisplayInBOM on all Subs in an Assembly

    Cad Admin

      Is it possible to use ChildComponentDisplayInBOM in an assembly to check all subs, or so i need to check all the subs individually?

        • Re: API - VBA Check ChildComponentDisplayInBOM on all Subs in an Assembly
          Josh Brady

          This is a property of a configuration of an assembly.

          When the assembly is used as a subassembly, this property controls how it is shown in the BOM.

          If the assembly is used as a top-level assembly, this property has no meaning.

          The property does not cascade down.  If this assembly contains subassemblies, each one of them has their own property on a config-by-config basis.

           

          It's just the API way to get to this option:

           

          Try each one yourself to understand how they work.

          • Re: API - VBA Check ChildComponentDisplayInBOM on all Subs in an Assembly
            Cad Admin

            Ya, i figured, this was more a top level question, if anyone had done it...i didn't find to much on the ChildComponentDisplayInBOM. I also added the check for skipping suppressed items.

             

            Option Explicit

             

            Sub TraverseComponent _

            (swComp As SldWorks.Component2, nLevel As Long)

               

                Dim swModel                 As SldWorks.ModelDoc2

                Dim swConfigMgr             As SldWorks.ConfigurationManager

                Dim vChildComp              As Variant

                Dim swChildComp             As SldWorks.Component2

                Dim swCompConfig            As SldWorks.Configuration

                Dim sPadStr                 As String

                Dim i                       As Long

                Dim CheckPromote            As Integer

                Dim CheckResults            As String

               

                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

                   

                    If swChildComp.IsSuppressed = False Then

                        Set swModel = swChildComp.GetModelDoc2

                        Set swCompConfig = swModel.GetActiveConfiguration

                        CheckPromote = swCompConfig.ChildComponentDisplayInBOM

                       

                        If CheckPromote = 1 Then

                            CheckResults = "Hide"

                        End If

                       

                        If CheckPromote = 2 Then

                            CheckResults = "Show"

                        End If

                       

                        If CheckPromote = 3 Then

                            CheckResults = "Promote"

                        End If

                       

                        If swModel.GetType = swDocASSEMBLY Then

                           Debug.Print "Assembly Name: "; swChildComp.Name2

                           Debug.Print "     Configuration: " & swChildComp.ReferencedConfiguration

                           Debug.Print "     Child Component Display When used in a Subassembly: " & CheckResults

                        End If

                    End If

                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

                Dim fileName                As String

                Dim errors                  As Long

                Dim warnings                As Long

             

                Set swApp = Application.SldWorks

                Set swModel = swApp.ActiveDoc

             

                Set swConf = swModel.GetActiveConfiguration

                Set swRootComp = swConf.GetRootComponent3(True)

             

                ' Traverse components

                TraverseComponent swRootComp, 1

             

            End Sub

             

             

             

             

            As always thanks for the assist

            • Re: API - VBA Check ChildComponentDisplayInBOM on all Subs in an Assembly
              Cad Admin

              good catch, i will add it in as well..thx