AnsweredAssumed Answered

What do I add to a macro to quit if a condition is met?

Question asked by Chris Canterbury on May 22, 2015
Latest reply on May 22, 2015 by Jim Sculley

I downloaded this macro a year or so ago, and it works quite well.  My only issue is that it errors if there are no configuration specific data to remove.

 

I've coded a bit in C, C++, Java, and Java Script, but Visual Basic baffles me.  I tried to add an If statement to quit if there are no config specific data, but that didn't work as I thought it would.

 

What statement do I add, and where do I add it, to make this a macro I can run on anything, any number of times?

 

Thanks!

 

Dim swApp As Object

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swCustPropMgr As SldWorks.CustomPropertyManager

Dim vConfigNames As Variant

Dim vCustPropNames As Variant

Dim i As Integer

Dim j As Integer

 

Sub deleteConfigProps()

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    vConfigNames = swModel.GetConfigurationNames

       

        'Loop through all configurations

    For i = 0 To UBound(vConfigNames)

        Set swCustPropMgr = swModel.Extension.CustomPropertyManager(vConfigNames(i))

        vCustPropNames = swCustPropMgr.GetNames

        'Loop through and delete all configuration properties

        For j = 0 To UBound(vCustPropNames)

            swCustPropMgr.Delete vCustPropNames(j)

        Next j

    Next i

End Sub

Outcomes