Suppress or unsuppress the Flatten feature of Sheet metal part ?

Hi Budy,

As the topic said, I am using Macro (.swp) to suppress/unsuppress the flatten feature of a sheet metal part.

However, when I am using traversing method to get the flatten feature, it was always fail. while it ran very OK in selecting by click the flatten feature.

can you point out what is the problem ? thank you very much .

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.traversing method>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

   Sub main()

    Dim swApp               As SldWorks.SldWorks

    Dim swModel             As SldWorks.ModelDoc2
   
    Dim swFeature           As SldWorks.Feature
   
    Set swApp = CreateObject("SldWorks.Application")
   
    Set swModel = swApp.ActiveDoc

                If Not swModel Is Nothing Then
                
                    Set swFeature = swModel.FirstFeature
                   
                    While Not swFeature Is Nothing
                   
                    If swFeature.GetTypeName = "FlatPattern" Then  ' to detect if it is Flatten feature
                     
                        Dim isSuppressed As Boolean
   
                            isSuppressed = swFeature.isSuppressed
                           
                            Debug.Print swFeature.Name & "   IsSuppressed =   " & isSuppressed      ' it can always get the data here
                           
                            If isSuppressed = True Then  'if it is suppresseed
                           
                                swFeature.SetSuppression (1)  'then unsuppressed
                               
                            End If
                           
                    End If

                    swFeature.SetUIState swIsHiddenInFeatureMgr, False
                                                      
                    swModel.EditRebuild3

                        Set swFeature = swFeature.GetNextFeature
                      Wend
                End If
               
   End Sub

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.Selecting Method:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swSelMgr As SldWorks.SelectionMgr
    Dim swFeat As SldWorks.Feature

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
       
    Dim isSuppressed As Boolean
   
    isSuppressed = swFeat.isSuppressed
   
    If isSuppressed = False Then
        swFeat.SetSuppression (0)
    Else
       swFeat.SetSuppression (1)
    End If

End Sub

SolidworksApi macros