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
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.