Skip to content

Instantly share code, notes, and snippets.

@AmenJlili
Created August 4, 2020 01:55
Show Gist options
  • Save AmenJlili/722af434c426f16378dc127587401dc1 to your computer and use it in GitHub Desktop.
Save AmenJlili/722af434c426f16378dc127587401dc1 to your computer and use it in GitHub Desktop.
Delete all properties for the active configuration – SOLIDWORKS MACRO
' Delete all properties from the active configuration
' Conditions = None
' Results = all properties in the active configuration are deleted
' www.bluebyte.biz
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
End If
If swModel.GetType = swDocumentTypes_e.swDocDRAWING Then
swApp.SendMsgToUser "Drawings do not have configurations"
End
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
Else
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
@dinhquyet123
Copy link

I can macro delete custom property and configuration part and assembly .
i have code:
Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim sFilePath As String
Dim sFileName As String

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
sFileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)
sFilePath = swModel.GetPathName
swModel.DeleteCustomInfo "SL"
End Sub

code of my non delete configuration.
plese help me. thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment