8 Replies Latest reply on Aug 2, 2018 2:23 PM by Sam Pike

    Assembly Linear Component Pattern

    Sam Pike

      Hi guys, have question about assembly linear component patterns.

      I updated my template that has screw-on locating pins.

      The locating pins are used in a linear component pattern in the assembly and I renamed it to "LocatingPinPattern". The pins are held in place, with bolts, on a base plate which is another part in the assembly.

      On the base plate, I have a linear component pattern for the bolt holes.

      I decided to make an api, with a form, for the user to input and adjust the LocatingPinPattern Distance and Number of Instances. Everything works great.

      I then decided to take it another step further and made global variables in the assembly for the D3 and D1 dimension of the LocatingPinPattern and called them ComponentPatternDistance and ComponentPatternInstance and linked them to the Bolt Hole Pattern.

       

      Now my code does not work anymore after the linking. I tried changing the variables in the code to different things to get it to work. Does anyone have any idea how to get this to work?

       

      Dim swApp As SldWorks.SldWorks
      Dim swPart As SldWorks.ModelDoc2
      Dim boolstatus As Boolean
      Dim swDim As Object
      Dim swDim2 As Object

       

      Private Sub cmdUpdateValues_Click()

       

      Set swApp = Application.SldWorks
      Set swPart = swApp.ActiveDoc

       

      'Getting the Assembly pattern
      boolstatus = swPart.Extension.SelectByID2("LocatingPinPattern", "COMPPATTERN", 0, 0, 0, False, 0, Nothing, 0)

       

      'Setting the number of instances for the Assembly Pattern
      Set swDim = swPart.Parameter("ComponentPatternInstance@LocatingPinPattern")
      swDim.Value = txtInstance.Text 'Text taken from user form

       

      'Setting the spacing value for the Assembly Pattern
      Set swDim2 = swPart.Parameter("ComponentPatternDistance@LocatingPinPattern")
      swDim2.Value = txtDistance.Text  'Text taken from user form

      swPart.ForceRebuild3 (True)

       

      End Sub

       

      Private Sub UserForm_Initialize()

      Dim swDim As Object
      Dim swDim2 As Object


      End Sub

        • Re: Assembly Linear Component Pattern
          Nilesh Patel

          Hi Sam,

           

          Once you select the linear component pattern, you will need to get 'ILocalLinearPatternFeatureData' object. Then access the feature, modify your parameters and then modify the feature.

           

          Have a look at the following example as a reference: 2017 SOLIDWORKS API Help - Get and Set Seed Components Example (VBA)

           

          Regards,

          Nilesh

          • Re: Assembly Linear Component Pattern
            Josh Brady

            Sam Pike wrote:

             

            I then decided to take it another step further and made global variables in the assembly for the D3 and D1 dimension of the LocatingPinPattern and called them ComponentPatternDistance and ComponentPatternInstance and linked them to the Bolt Hole Pattern.

             

            Now my code does not work anymore after the linking.

             

             

            Why did you "take it another step further"?  What were you trying to accomplish with that?  Just trying to understand because it was working before.... so why change it?

             

            Also, with apologies, IMHO Nilesh's direction is not correct for you. 

             

            Number of instances in a pattern is a dimension.  Your code can find any dimension and change it.  So that works.

            The problem is that you've told that dimension to be driven by a global variable.  So you try to set the dimension with code and it goes "no way, Sammy, I'm linked to a variable!"

             

            You can't get to global variables with the Parameter thing you have here.  You have to go through the EquationManager.  If you go through EquationManager you can change global variables. 

             

            But why do that?  Just get rid of the global variables.  You can re-name the dimension to be something instead of D1 and D3, then change your code correspondingly.

              • Re: Assembly Linear Component Pattern
                Nilesh Patel

                Thanks for correcting me Josh Brady

                • Re: Assembly Linear Component Pattern
                  Sam Pike

                  I am still pretty new too this Josh. In the grand scheme of things, I have a master form that opens up with all the steps in order to change the asssembly file/template. At each step, you hit a button and it runs code for that step. This is one of the steps, to update the main assembly‘s pattern and then update the corresponding bolt holes for it. It always has to be done. I figured an api would be good or a variable.

                   

                  Since I am new to this, I have been doing ok traversing top level in an assembly, otherwise I would have followed on with coding it out. But when it gets down to another part’s feature in the assembly, I am having trouble understanding how to do this due to my lack of knowledge. I belive I would need to do a loop or recusion

                   

                  But at the same time, I am trying to keep the user input on the form and not having to go and find the pattern manually. Unfortunately I would still like to have that option though.

                   

                  Ironacally since this is starting to take shape, people are worried that I am taking away from there job, which is way far from the truth.

                   

                  So it looks like I will be looking into EquationManager.

                    • Re: Assembly Linear Component Pattern
                      Josh Brady

                      I don't think you need the EquationManager.

                       

                      You can link your part file's pattern dimensions directly to the assembly pattern feature's dimensions without going through a variable.  When your code changes component pattern spacing/qty in the assembly (just like it did before), the base plate part hole pattern will also change because its dimension is linked to the assembly.

                       

                      Also, you don't need your SelectByID2 line.  All that line does is select the feature.  But the line:

                      Set swDim = swPart.Parameter("ComponentPatternInstance@LocatingPinPattern")

                      gets the dimension of interest regardless of whether or not the feature is selected.  Now, the stuff above in quotes needs to be the exact name of the dimension you're trying to get.  It's the same text that shows up in the Property Manager on the left side when you select the dimension with the mouse. 

                        • Re: Assembly Linear Component Pattern
                          Sam Pike

                          Josh, I have been going on this all morning. Hoping you can help me out here one last time? I am able to create a linked value name in the assembly and in the part, but I cannot figure out how to link the two together without creating a variable. Could you step or point me on how to do this? I am using SW2018 if that matters also.

                            • Re: Assembly Linear Component Pattern
                              Deepak Gupta

                              Sam Pike wrote:

                               

                              but I cannot figure out how to link the two together without creating a variable.

                              Double click on the part dimension and edit it. Now while in edit mode, double click on the feature that would show the assembly dimension name. In the part edit dimension box type = and then select the assembly dimension.

                               

                              If this does not work then get (copy) the assembly dimension name. Noe edit the part dimension, type =" paste the assembly dimension name and end with "