2 Replies Latest reply on Sep 8, 2015 9:46 AM by Arvind Purushotaman

    Getting Components other than suppressed from the assembly treee

    Arvind Purushotaman

      Hello,

       

      I am trying to get the parts from the assembly tree that are unsuppressed. Can you guys help with the mistake. I am fairly new and I am learning.

       

      Dim swApp As SldWorks.SldWorks

      Dim swModel As SldWorks.ModelDoc2

      Dim swFeat As SldWorks.Feature

      Dim testModel As Component2

      Dim entity As entity

      Dim component As Component2

       

      Sub main()

       

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

       

          Set swFeat = swModel.FirstFeature

         

          While Not swFeat Is Nothing

                  Set testModel = swFeat.GetSpecificFeature2

                  If testModel.GetSuppression = 0 Then

                      MsgBox "Part Suppressed"

                  Else

                      Set entity = swFeat

                      If entity.GetType = swSelectType_e.swSelCOMPONENTS Then

                          Set component = swFeat.GetSpecificFeature2

                          MsgBox "Name: " & component.Name2

                      End If

                  End If

                 

                  Set swFeat = swFeat.GetNextFeature

          Wend

      End Sub

       

      The bold sentence is where I am getting an error.

       

      Thank you,

        • Re: Getting Components other than suppressed from the assembly treee
          Deepak Gupta

          You need to get components and not features

           

          Option Explicit

          Sub Main()

              Dim swApp                   As SldWorks.SldWorks

              Dim swModel                 As SldWorks.ModelDoc2

              Dim Children                As Variant

              Dim swChild                 As SldWorks.Component2

              Dim i                       As Long

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Children = swModel.ConfigurationManager.ActiveConfiguration.GetRootComponent.GetChildren

                For i = 0 To UBound(Children)

                  Set swChild = Children(i)

                      If swChild.GetSuppression <> 0 Then Debug.Print swChild.Name2

              Next i

          End Sub

            • Re: Getting Components other than suppressed from the assembly treee
              Arvind Purushotaman

              That makes sense.

              But the snippet that I gave gets me the component's name when I run only the else loop in If loop that is ,

               

              Dim swApp As SldWorks.SldWorks

              Dim swModel As SldWorks.ModelDoc2

              Dim swFeat As SldWorks.Feature

              Dim entity As entity

              Dim component As Component2

               

              Sub main()

               

                  Set swApp = Application.SldWorks

                  Set swModel = swApp.ActiveDoc

               

                  Set swFeat = swModel.FirstFeature

                

                  While Not swFeat Is Nothing

                              Set entity = swFeat

                              If entity.GetType = swSelectType_e.swSelCOMPONENTS Then

                                  Set component = swFeat.GetSpecificFeature2

                                  MsgBox "Name: " & component.Name2

                              End If

                          End If

                        

                          Set swFeat = swFeat.GetNextFeature

                  Wend

              End Sub

               

              Does that make a component a subset of feature?

              If that is so, can we access a component though features?