We are trying to loop through all components of a pattern (chain pattern) in order to suppress every 5th (or rather n-th) component of that pattern.
Is it possible to loop through a selected pattern?
We are trying to loop through all components of a pattern (chain pattern) in order to suppress every 5th (or rather n-th) component of that pattern.
Is it possible to loop through a selected pattern?
Thanks for your response.
The line "Set FeatureData = swPattern.GetDefinition" throwns an error for me if I use it with a linear pattern.
The actual usecase is with chain patterns inside assemblies. I modified the data type to "Dim FeatureData As SldWorks.ChainPatternFeatureData" but the method of skipping / suppressing single features seems different for chain patterns. FeatureData.SkippedItemArray = swSkippedPattern does not work
Also we would like to skip every 5th element, not only exactly the fifth.
For Chain pattern:
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swPattern As SldWorks.Feature
Dim FeatureData As SldWorks.ChainPatternFeatureData
Dim swSubFeat As SldWorks.Feature
Dim swComp As SldWorks.Component2
Dim boolstatus As Boolean
Dim i As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
'boolstatus = swModel.Extension.SelectByID2("ChainPattern1", "COMPPATTERN", 0, 0, 0, False, 0, Nothing, 0)
Set swPattern = swSelMgr.GetSelectedObject6(1, -1)
If swPattern Is Nothing Then
MsgBox "Can't find pattern"
Exit Sub
End If
Set FeatureData = swPattern.GetDefinition
If FeatureData Is Nothing Then
MsgBox "Can't find pattern data"
Exit Sub
End Ifi = 0
swModel.ClearSelection2 True
Set swSubFeat = swPattern.GetFirstSubFeature
While Not swSubFeat Is Nothing
i = i + 1
If i Mod 5 = 0 Then
Set swComp = swSubFeat.GetSpecificFeature2
swComp.Select4 True, Nothing, False
End If
Set swSubFeat = swSubFeat.GetNextSubFeature
Wend
swModel.EditSuppress2
End Sub
Hello. Select a Linear Pattern with at last 5 components, then run this macro:
It will skip the 5th instance.