SUPPRESS PART IN ASSEMBLY VIA API

Good Friday to you all!

I have a macro that should suppress all hardware(we name them with a 5 number) but for some reason it just isnt suppressing them. Anything you can tell me will be helpful.

Ive included my code for perusing.

Thanks,

Trevor

Option Explicit

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim boolStatus As Boolean

Dim feat As Object

Dim featureName As String

Const SWDOCPART = 1

Const SWDOCASSEMBLY = 2

Const SWDOCDRAWING = 3

Dim vConfigName As Variant

Dim sConfigName As String

Dim i As Long

Dim swConfig As SldWorks.Configuration

Dim swSubFeat As SldWorks.Feature

Dim subFeatName As String

Sub main()

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Dim configMgr As ConfigurationManager

    Dim C1a As Configuration

    Dim selMgr As SelectionMgr

    Dim res As Variant

    Dim itemNumber As String  

    Set selMgr = swModel.SelectionManager

    Set configMgr = swModel.ConfigurationManager   

    swModel.ShowConfiguration2 ("Default")

   

'New code to find configuration names

    Set swConfig = swModel.GetActiveConfiguration

    vConfigName = swModel.GetConfigurationNames

   

    For i = 0 To UBound(vConfigName)

   

        sConfigName = vConfigName(i)

         

        Set swConfig = swModel.GetConfigurationByName(sConfigName)

            

        If sConfigName = "Default" Then

       

       

        ElseIf sConfigName = "NO HARDWARE" Then

           

            'make flat pattern active configuration

            swModel.ShowConfiguration2 ("NO HARDWARE")

       

  

            Set feat = swModel.FirstFeature

   

            Do While Not feat Is Nothing

   

            Let featureName = feat.Name

           

            itemNumber = Left(featureName, 1)

           

            If itemNumber = "5" Then

                res = swModel.SelectByID(featureName, "BODYFEATURE", 0, 0, 0)

                res = swModel.EditSuppress()

           

                Set swSubFeat = feat.GetFirstSubFeature

          

               

                    While Not swSubFeat Is Nothing

                        Let subFeatName = swSubFeat.Name

                        res = swModel.SelectByID(subFeatName, "BODYFEATURE", 0, 0, 0)

                        res = swModel.EditSuppress()

                        Set swSubFeat = swSubFeat.GetNextSubFeature

                    Wend

            Else

            End If

               

   

            Set feat = feat.GetNextFeature()

            Loop

       

            'set back to the correct configuration

            swModel.ShowConfiguration2 ("Default")

        End

       

        End If

      

    Next

'End new code

   

    'create flat pattern configuration

   

    configMgr.AddConfiguration "NO HARDWARE", "NO HARDWARE", "Alternate Name", 1, "Default", "no description"

 

    Set feat = swModel.FirstFeature

   

    Do While Not feat Is Nothing

   

    Let featureName = feat.Name

   

    itemNumber = Left(featureName, 1)

   

    If itemNumber = "5" Then

        res = swModel.SelectByID(featureName, "BODYFEATURE", 0, 0, 0)

        res = swModel.EditUnsuppress()

   

        Set swSubFeat = feat.GetFirstSubFeature

   

            While Not swSubFeat Is Nothing

                Let subFeatName = swSubFeat.Name

                res = swModel.SelectByID(subFeatName, "BODYFEATURE", 0, 0, 0)

                res = swModel.EditUnsuppress()

                Set swSubFeat = swSubFeat.GetNextSubFeature

            Wend

        Else

    End If

   

   

    Set feat = feat.GetNextFeature()

    Loop

       

    'set back to the correct configuration

    swModel.ShowConfiguration2 ("Default")

   

   

   

End Sub

SolidworksApi macros