Delete all properties for the active configuration – SOLIDWORKS MACRO

Amen Jlili

The following macro deletes all the properties from the active configuration. The macro is written used late-binding so it is version independant.
The deletion action will be confirmed by the user.

' Delete all properties from the active configuration
' Conditions = None
' Results = all properties in the active configuration are deleted

Dim swApp As Object
Dim swModel As Object
Dim CustomPropertyManager As Object

Public Enum swDocumentTypes_e
swDocDRAWING = 3
End Enum

Sub Main()
'get pointer to the solidworks application
Set swApp = Application.SldWorks
'get active document
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
    swApp.SendMsgToUser "There is no active document"
End If

If swModel.GetType = swDocumentTypes_e.swDocDRAWING Then
    swApp.SendMsgToUser "Drawings do not have configurations"
End If

'get the active configuration name
Dim activeConfigurationName As String
activeConfigurationName = swModel.GetActiveConfiguration.Name
Set CustomPropertyManager = swModel.Extension.CustomPropertyManager(activeConfigurationName)

'get property names
Dim propertyNames As Variant
propertyNames = CustomPropertyManager.GetNames

'define dialog answer
Dim answer As Long

'exit sub if there are no properties
If IsEmpty(propertyNames) Then
    swApp.SendMsgToUser "Configuration " & activeConfigurationName & " has no properties to delete!"
    Exit Sub
    answer = MsgBox("You are about to delete all properties from the configuration " & ActiveConfiguration & ". Are you sure you want to proceed?", vbYesNo + vbQuestion)
    If answer = vbNo Then
    Exit Sub
    End If
End If

'delete properties
For i = 0 To UBound(propertyNames)
    CustomPropertyManager.Delete2 propertyNames(i)
Next i

End Sub

Problems running the macro? Report a bug here.

More great articles

Export SOLIDWORKS BOM to Excel with thumbnail preview – SOLIDWORKS MACRO

xlBOM with thumbnails - SOLIDWORKS add-in We released a premium add-in that exports BOM with thumbnails. More information here. ×…

Read Story

Top reasons to upgrade your VBA macros in 2020

VBA macros continue to be the choice of the SOLIDWORKS community for automating repetitive tasks. After years of contributing to…

Read Story