Having problems with getting SetSuppression2 and ClearSelection2 to work on selected components from FeatureManager. SetSuppression2 not changing the component to the choice of suppression and ClearSelection2 not releasing. Create an ASSY then add some Sub ASSY and PARTS. Make sure they are fully resolved and select a couple from the FeatureManager and run Macro. Look at debug screen. Suppression STATE should be 1 not 2 on components. Running SW2009 SP3 on Vista 32-bit.
' ------------ START CODE ------------
Option Explicit
Sub main()
On Error Resume Next
Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swComp As SldWorks.Component2
Dim CompArry() As Variant, CompCnt As Long, CompSelChk As Boolean
Dim nSelCount As Long
Dim CompSSSC As Integer
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set swSelMgr = swDoc.SelectionManager
nSelCount = swSelMgr.GetSelectedObjectCount2(-1)
If nSelCount < 1 Then
Debug.Print "Selected Components = " & nSelCount & vbCr & "Select Components from FeatureManager and run again." & vbCr
Exit Sub
End If
ReDim CompArry(0)
For CompCnt = 1 To nSelCount
Set swComp = swSelMgr.GetSelectedObjectsComponent3(CompCnt, -1)
If UBound(CompArry) <= 0 And CompSelChk = False Then ' Component Array doesn't exist - Create it
ReDim CompArry(0): Set CompArry(0) = swComp
CompSelChk = True
ElseIf UBound(CompArry) >= 0 And CompSelChk = True Then ' Component Array exist - Populate it
ReDim Preserve CompArry(UBound(CompArry) + 1): Set CompArry(UBound(CompArry)) = swComp
End If
Next CompCnt
For CompCnt = LBound(CompArry) To UBound(CompArry)
Set swComp = CompArry(CompCnt)
CompSSSC = swComp.SetSuppression2(1) 'swComponentLightweight
Debug.Print "Comp: " & swComp.Name2 & vbCr & "--> State: " & swComp.GetSuppression() & vbCr & "--> Error: " & CompSSSC
Next CompCnt
swDoc.ClearSelection2 (True)
End Sub
