Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim cpm As CustomPropertyManager
Sub DeleteProps()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Dim names() As String
Set cpm = swModel.Extension.CustomPropertyManager("")
names = cpm.GetNames
Dim i As Integer
For i = 0 To UBound(names)
Debug.Print names(i)
If names(i) <> "PROP1" Or names(i) <> "PROP2" Or names(i) <> "PROP3" Then cpm.Delete names(i)
Next
End Sub
Or if you have the tools, use the smartproperties tool of the Mycadtools utilities.
With this utility you can even apply it in batches.
Dim swApp As SldWorks.SldWorks Dim swModel As ModelDoc2 Dim cpm As CustomPropertyManager
Sub DeleteProps()
Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc
Dim names() As String
Set cpm = swModel.Extension.CustomPropertyManager("") names = cpm. GetNames
Dim i As Integer For i = 0 To UBound(names) Debug.Print names(i) If names(i) <> "CODE_ARTICLE" Or names(i) <> "NUMERO_PLAN" Then cpm. Delete names(i) Next
Sorry you have to put an and instead of gold because you erase so different from pop& and so different from prop2
Be careful, the breakage is important.
If necessary for the test phase you can try this:
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim cpm As CustomPropertyManager
Sub DeleteProps()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Dim names() As String
Set cpm = swModel.Extension.CustomPropertyManager("")
names = cpm.GetNames
Dim i As Integer
For i = 0 To UBound(names)
Debug.Print names(i)
If names(i) <> "Prop1" And names(i) <> "Prop2" Then Debug.Print names(i) & ": Effacé"
'If names(i) <> "Prop1" And names(i) <> "Prop2" Then cpm.Delete names(i)
Next
End Sub
And then you edit your macro and you launch it from the editor. And you check your execution window, it shows you the name of the property and then the name of the property: Deleted if it needs to delete it. Otherwise, it moves on to the next property.