Looking to select All patterned components in All patterns in an assembly. I don't want to include the Seed, if this can be done.
This should get you started:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeature As SldWorks.Feature
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeature = swModel.FirstFeature
Do While (Not (swFeature Is Nothing))
Debug.Print "Feature Name: " & swFeature.Name
Debug.Print " Feature Type: " & swFeature.GetTypeName2
If swFeature.GetTypeName2 = "ReferencePattern" Then
swFeature.Select2 True, 1
Set swFeature = swFeature.GetNextFeature
Once again you "filled in the blanks"...LOL. My issues is I believe with looping the macro will fairly slow, i have some assembly with 500+ components & 20-50+ patterns. Would any other way run faster, just a side question?
Nothing I can think of, other than possibly disabling graphics updating. This does top-level only, so it won't select patterned components of subassemblies. You may have to use a different approach if you need to select subassembly patterns in the context of the top level. The actual looping is very high level (just the feature tree basically), so it should be pretty quick. Graphics updating as the component is selected is probably the most time consuming. I don't know of a way to "batch select" a bunch of things all at once in the API.
Yes i agree the transition i set to "0"
boolstatus = swApp.SetUserPreferenceDoubleValue(swUserPreferenceDoubleValue_e.swViewTransitionHideShowComponent, 0)
Then right before the end i reset it back to "0.625"
boolstatus = swApp.SetUserPreferenceDoubleValue(swUserPreferenceDoubleValue_e.swViewTransitionHideShowComponent, 0.625)
I can run this as is and see if my guys complain too much on the speed issue, never know they might be fine with it.
I just saw this too...
Get Component in a Linear Pattern
#CODE|Get Components From Local Pattern
Would it be possible or fees-able to do as was done there and jump right to a "subfeature", knowing that all patters are "subfeatures" instead of processing all features and looking for "ReferencePattern"? Shouldn't this speed up the selection? Just a thought
To do that you somehow you have to find the pattern feature in the assembly. The best way (other than user pre-selection) is to traverse the feature tree looking for pattern features. You can then get the sub-features from the pattern feature. However, SW still has to traverse the whole tree to find the pattern features. Might as well just grab the "ReferencePattern" features as you come across them.
If you actually care which pattern feature the instances come from, you do need to do the sub-feature thing. However, if you'll examine the immediate window after running the code I posted above, you'll see that SW actually finds the "ReferencePattern" features before it finds the actual pattern feature that generates them. Traversing subfeatures would actually end up being slower.
Got it, Just fount that thread at the last minute. and i understand your solution and reasoning. Thanks again.
Retrieving data ...