I'm looking to remove all but some properties in all PRT, ASM and DRW file @ configurations.
I found this code that removes all the properties in the configurations, which I adapted a bit.
How do I exclude multiple properties? The code removes a variable.
In my case, DESIGNATION_FR, DESIGNATION_UK, CODE_ARTICLE and NUM_PLAN
Option Explicit Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swConfig As SldWorks.Configuration Dim swCustPropMgr As SldWorks.CustomPropertyManager Dim vPropNames As Variant Dim vPropName As Variant Dim configNames As Variant Dim configName As Variant Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
swApp.SendMsgToUser2 "Open Part File", swMbWarning, swMbOk
Exit Sub
End If
If swModel.GetType <> swDocPART Then
swApp.SendMsgToUser2 "Open Part File", swMbWarning, swMbOk
Exit Sub
End If
configNames = swModel.GetConfigurationNames
For Each configName In configNames Set swConfig = swModel.GetConfigurationByName(configName) Set swCustPropMgr = swConfig.CustomPropertyManager vPropNames = swCustPropMgr.GetNames For Each vPropName In vPropNames If vPropName <> "DESIGNATION_FR" Then swCustPropMgr.Delete vPropName End If Next
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swConfig As SldWorks.Configuration
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim vPropNames As Variant
Dim vPropName As Variant
Dim configNames As Variant
Dim configName As Variant
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
swApp.SendMsgToUser2 "Ouvrir un fichier pièce", swMbWarning, swMbOk
Exit Sub
End If
If swModel.GetType <> swDocPART Then
swApp.SendMsgToUser2 "Ouvrir un fichier pièce", swMbWarning, swMbOk
Exit Sub
End If
Set swCustPropMgr = swModel.Extension.CustomPropertyManager(Empty)
vPropNames = swCustPropMgr.GetNames
For Each vPropName In vPropNames
If vPropName <> "DESIGNATION_FR" AND vPropName <> "DESIGNATION_UK" AND vPropName <> "CODE_ARTICLE" AND vPropName <> "NUM_PLAN" Then
swCustPropMgr.Delete vPropName
End If
Next
configNames = swModel.GetConfigurationNames
For Each configName In configNames
Set swConfig = swModel.GetConfigurationByName(configName)
Set swCustPropMgr = swConfig.CustomPropertyManager
vPropNames = swCustPropMgr.GetNames
For Each vPropName In vPropNames
If vPropName <> "DESIGNATION_FR" AND vPropName <> "DESIGNATION_UK" AND vPropName <> "CODE_ARTICLE" AND vPropName <> "NUM_PLAN" Then
swCustPropMgr.Delete vPropName
End If
Next
Next
End Sub
This probably comes from the fact that you don't have any properties in the config in question, you can do a test by putting:
If IsEmpty(vPropNames) = False Then
For Each vPropName In vPropNames
If vPropName <> "DESIGNATION_FR" And vPropName <> "DESIGNATION_UK" And vPropName <> "CODE_ARTICLE" And vPropName <> "NUM_PLAN" Then
swCustPropMgr.Delete vPropName
End If
Next
End If