10 Replies Latest reply on Oct 22, 2018 1:53 PM by Hepzibah Chandranand

    Visibility of component

    Hepzibah Chandranand

      Hi,

       

      I select the root component and hide all components using the context menu on right click.

       

      Using the API, when i check the visibility property of a component in a child assembly, it is still true.

       

      How do I get the correct state of a component using the API?

        • Re: Visibility of component
          Fifi Riri

          Hello, try this:

           

          Dim swApp As SldWorks.SldWorks

          Dim swAssy As SldWorks.AssemblyDoc

          Sub main()

              Set swApp = Application.SldWorks

              Dim swConf As SldWorks.Configuration

              Dim swRootComp As SldWorks.Component2

              Set swAssy = swApp.ActiveDoc

              Set swConf = swAssy.GetActiveConfiguration

              Set swRootComp = swConf.GetRootComponent3(True)

              TraverseComponent swRootComp

          End Sub

           

          Sub TraverseComponent(swComp As SldWorks.Component2)

              Dim vChilds As Variant, vChild As Variant

              Dim swChildComp As SldWorks.Component2

              vChilds = swComp.GetChildren

              For Each vChild In vChilds

                  Set swChildComp = vChild

                  If swChildComp.Visible = 0 Then

                      Debug.Print "Part Name : " & swChildComp.Name2 & " is hidden"

                  Else

                      Debug.Print "Part Name : " & swChildComp.Name2 & " is visible"

                  End If

                  TraverseComponent swChildComp

              Next

          End Sub

            • Re: Visibility of component
              Hepzibah Chandranand

              Thank you for your reply.

              Using your code you should be able to check the following:

               

              The visibility property of the child components in sub-assemblies are incorrect.

               

              Root => Right click and hide

              -Part01 => visible = false

              -Part02 => visible = false

              -Assembly1

                   -Part12 => visible = true though it is hidden

                   -Part13 => visible = true though it is hidden

              -Assembly2

               

              I would like to get the correct visibility value of Part12.

                • Re: Visibility of component
                  Fifi Riri

                  How about this:

                   

                  Dim swApp As SldWorks.SldWorks

                  Dim swAssy As SldWorks.AssemblyDoc

                  Sub main()

                      Set swApp = Application.SldWorks

                      Dim swConf As SldWorks.Configuration

                      Dim swRootComp As SldWorks.Component2

                      Set swAssy = swApp.ActiveDoc

                      Set swConf = swAssy.GetActiveConfiguration

                      Set swRootComp = swConf.GetRootComponent3(True)

                      TraverseComponent swRootComp, False

                  End Sub

                   

                  Sub TraverseComponent(swComp As SldWorks.Component2, Hidden As Boolean)

                      Dim vChilds As Variant, vChild As Variant

                      Dim swChildComp As SldWorks.Component2

                      vChilds = swComp.GetChildren

                      For Each vChild In vChilds

                          Set swChildComp = vChild

                          If Hidden Or swChildComp.Visible = 0 Then

                              Debug.Print "Part Name : " & swChildComp.Name2 & " is hidden"

                              TraverseComponent swChildComp, True

                          Else

                              Debug.Print "Part Name : " & swChildComp.Name2 & " is visible"

                              TraverseComponent swChildComp, False

                          End If

                      Next

                  End Sub

                    • Re: Visibility of component
                      Hepzibah Chandranand

                      Thank you for the reply with changes.

                      It almost works but not perfectly.

                      For some parts, it still says visible even though it is hidden.

                       

                      And for a huge project, changing the "Visible" property to the correct value is highly time consuming.

                       

                      Solidworks changes the icon correctly and also displays the contextmenu item (hide/show) correctly though the visible property is incorrect.

                      How is it done? its a puzzle.