Je cherche a supprimer toutes les propriétées sauf certaines , dans toutes les configurations et @ de fichier PRT, ASM et DRW.
J'ai trouvé ce code qui supprime toutes les propriétés dans les configurations, que j'ai adapté un peu.
Comment exclure plusieurs propriétés ? Le code supprime une variable.
Dans mon cas DESIGNATION_FR, DESIGNATION_UK, CODE_ARTICLE et 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 "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
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
Cela vient probablement du fait que tu n'as aucune propriété dans la config en question, tu peux faire un test en mettant :
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