12 Replies Latest reply on Mar 31, 2016 8:48 PM by Di Anne

    Get Component in a Linear Pattern

    Di Anne

      Hi SW Community,

       

      Does anyone know how to get the components inside a linear pattern?

       

      I'm using the code below but it doesn't work.

       

      LocalLinearPatternFeatureData llpDefinition = default(LocalLinearPatternFeatureData);
      llpDefinition = (LocalLinearPatternFeatureData)swFeature.GetDefinition();

      llpSeedComps = (object[])llpDefinition.SeedComponentArray;

       

      Thank you in advance.

       

      DiAnne

        • Re: Get Component in a Linear Pattern
          Artem Taturevych

          Hi Di Anne,

           

          Please take a look at this example: #CODE|Get Components From Local Pattern

           

          Thanks,
          Artem

            • Re: Get Component in a Linear Pattern
              Di Anne

              Hi Artem,

               

              I used the code you gave but I think SeedComponentArray refers to the base component.

              What I need is to get the list of component inside the pattern?

              So in my Pattern1, I need to get Comp1, Comp2, Comp3, & Comp4.

              Thank you.

               

              DiAnne

                • Re: Get Component in a Linear Pattern
                  Artem Taturevych

                  Hi,

                   

                  I understand. This example gets both seed components and components inside the pattern. If you do not want seed just remove the following lines form the example and the rest of the code will find and select the components generated by the pattern (the ones on your picture):

                   

                  If Not IsEmpty(vSeedComps) Then

                         

                          swModel.ClearSelection2 True

                         

                          Dim swComp As SldWorks.Component2

                          Dim i As Integer

                         

                          For i = 0 To UBound(vSeedComps)

                         

                              Set swComp = vSeedComps(i).GetSpecificFeature

                              Debug.Print swComp.Name2

                             

                              swComp.Select4 True, Nothing, False

                             

                          Next

                         

                          Dim swCompFeat As SldWorks.Feature

                          Set swCompFeat = swPattFeat.GetFirstSubFeature

                         

                          While Not swCompFeat Is Nothing

                         

                              Set swComp = swCompFeat.GetSpecificFeature2

                              Debug.Print swComp.Name2

                             

                              swComp.Select4 True, Nothing, False

                             

                              Set swCompFeat = swCompFeat.GetNextSubFeature

                             

                          Wend