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)
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.
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.
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.
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.
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 "
After a bunch of fiddling I finally got it to select. Component patterns dimensions are made in a weird position on the screen and were really hard to select. But I eventually got it to work. Thanks for all the help guys.